core (logs): added formatting, name filter and outputs management:
- formatting is inspired from, and use when possible, standard logging. "message", "levelname", and "name" are the only format managed, depending on backend more can be managed (standard backend formats are specified in official python logging doc)
- name filter use regular expressions. It's possible to log only plugins with SAT_LOG_LOGGER="^sat.plugins". To log only XEPs 96 & 65, we can use SAT_LOG_LOGGER='(xep_0095|xep_0065)'
- output management use a particular syntax:
- output handler are name with "//", so far there are "//default" (most of time stderr), "//memory" and "//file"
- options can be specified in parenthesis, e.g. "//memory(50)" mean a 50 lines memory buffer (50 is the current default, so that's equivalent to "//memory")
- several handlers can be specified: "//file(/tmp/sat.log)//default" will use the default logging + a the /tmp/sat.log file
- if there is only one handler, it use the file handler: "/tmp/sat.log" is the same as "//file(/tmp/sat.log)"
- not finished, need more work for twisted and basic backends
This commit is contained in:
parent
86d90d66aa
commit
64384dc8bf
1 changed files with 127 additions and 25 deletions
|
|
@ -80,8 +80,23 @@ class Const(object):
|
|||
LOG_BASE_LOGGER = 'root'
|
||||
LOG_OPT_PREFIX = 'log_'
|
||||
# (option_name, default_value) tuples
|
||||
LOG_OPT_COLORS = ('colors', 'true')
|
||||
LOG_OPT_COLORS = ('colors', 'true') # true for auto colors, force to have colors even if stdout is not a tty, false for no color
|
||||
LOG_OPT_LEVEL = ('level', 'info')
|
||||
LOG_OPT_FORMAT = ('fmt', '%(message)s') # similar to logging format.
|
||||
LOG_OPT_LOGGER = ('logger', '') # regex to filter logger name
|
||||
LOG_OPT_OUTPUT_SEP = '//'
|
||||
LOG_OPT_OUTPUT_DEFAULT = 'default'
|
||||
LOG_OPT_OUTPUT_MEMORY = 'memory'
|
||||
LOG_OPT_OUTPUT_MEMORY_LIMIT = 50
|
||||
LOG_OPT_OUTPUT_FILE = 'file' # file is implicit if only output
|
||||
LOG_OPT_OUTPUT = ('output', LOG_OPT_OUTPUT_SEP + LOG_OPT_OUTPUT_DEFAULT) # //default = normal output (stderr or a file with twistd), path/to/file for a file (must be the first if used), //memory for memory (options can be put in parenthesis, e.g.: //memory(500) for a 500 lines memory)
|
||||
LOG_OPTIONS = (LOG_OPT_COLORS, LOG_OPT_LEVEL, LOG_OPT_FORMAT, LOG_OPT_LOGGER, LOG_OPT_OUTPUT)
|
||||
LOG_LVL_DEBUG = 'DEBUG'
|
||||
LOG_LVL_INFO = 'INFO'
|
||||
LOG_LVL_WARNING = 'WARNING'
|
||||
LOG_LVL_ERROR = 'ERROR'
|
||||
LOG_LVL_CRITICAL = 'CRITICAL'
|
||||
LOG_LEVELS = (LOG_LVL_DEBUG, LOG_LVL_INFO, LOG_LVL_WARNING, LOG_LVL_ERROR, LOG_LVL_CRITICAL)
|
||||
|
||||
|
||||
## Misc ##
|
||||
|
|
@ -92,7 +107,7 @@ class Const(object):
|
|||
|
||||
## ANSI escape sequences ##
|
||||
# XXX: used for logging
|
||||
# XXX: there will be probably moved in a dedicated module in the future
|
||||
# XXX: they will be probably moved in a dedicated module in the future
|
||||
ANSI_RESET = '\033[0m'
|
||||
ANSI_NORMAL_WEIGHT = '\033[22m'
|
||||
ANSI_FG_BLACK, ANSI_FG_RED, ANSI_FG_GREEN, ANSI_FG_YELLOW, ANSI_FG_BLUE, ANSI_FG_MAGENTA, ANSI_FG_CYAN, ANSI_FG_WHITE = ('\033[3%dm' % nb for nb in xrange(8))
|
||||
|
|
|
|||
Loading…
Reference in a new issue