comparison src/core/constants.py @ 1005:b4af31a8a4f2

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
author Goffi <goffi@goffi.org>
date Mon, 05 May 2014 18:58:34 +0200
parents 191f440d11b4
children a7d33c7a8277
comparison
equal deleted inserted replaced
1004:191f440d11b4 1005:b4af31a8a4f2
78 LOG_BACKEND_TWISTED = 'twisted' 78 LOG_BACKEND_TWISTED = 'twisted'
79 LOG_BACKEND_BASIC = 'basic' 79 LOG_BACKEND_BASIC = 'basic'
80 LOG_BASE_LOGGER = 'root' 80 LOG_BASE_LOGGER = 'root'
81 LOG_OPT_PREFIX = 'log_' 81 LOG_OPT_PREFIX = 'log_'
82 # (option_name, default_value) tuples 82 # (option_name, default_value) tuples
83 LOG_OPT_COLORS = ('colors', 'true') 83 LOG_OPT_COLORS = ('colors', 'true') # true for auto colors, force to have colors even if stdout is not a tty, false for no color
84 LOG_OPT_LEVEL = ('level', 'info') 84 LOG_OPT_LEVEL = ('level', 'info')
85 LOG_OPT_FORMAT = ('fmt', '%(message)s') # similar to logging format.
86 LOG_OPT_LOGGER = ('logger', '') # regex to filter logger name
87 LOG_OPT_OUTPUT_SEP = '//'
88 LOG_OPT_OUTPUT_DEFAULT = 'default'
89 LOG_OPT_OUTPUT_MEMORY = 'memory'
90 LOG_OPT_OUTPUT_MEMORY_LIMIT = 50
91 LOG_OPT_OUTPUT_FILE = 'file' # file is implicit if only output
92 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)
93 LOG_OPTIONS = (LOG_OPT_COLORS, LOG_OPT_LEVEL, LOG_OPT_FORMAT, LOG_OPT_LOGGER, LOG_OPT_OUTPUT)
94 LOG_LVL_DEBUG = 'DEBUG'
95 LOG_LVL_INFO = 'INFO'
96 LOG_LVL_WARNING = 'WARNING'
97 LOG_LVL_ERROR = 'ERROR'
98 LOG_LVL_CRITICAL = 'CRITICAL'
99 LOG_LEVELS = (LOG_LVL_DEBUG, LOG_LVL_INFO, LOG_LVL_WARNING, LOG_LVL_ERROR, LOG_LVL_CRITICAL)
85 100
86 101
87 ## Misc ## 102 ## Misc ##
88 SAVEFILE_DATABASE = APP_NAME_FILE + ".db" 103 SAVEFILE_DATABASE = APP_NAME_FILE + ".db"
89 IQ_SET = '/iq[@type="set"]' 104 IQ_SET = '/iq[@type="set"]'
90 ENV_PREFIX = 'SAT_' # Prefix used for environment variables 105 ENV_PREFIX = 'SAT_' # Prefix used for environment variables
91 106
92 107
93 ## ANSI escape sequences ## 108 ## ANSI escape sequences ##
94 # XXX: used for logging 109 # XXX: used for logging
95 # XXX: there will be probably moved in a dedicated module in the future 110 # XXX: they will be probably moved in a dedicated module in the future
96 ANSI_RESET = '\033[0m' 111 ANSI_RESET = '\033[0m'
97 ANSI_NORMAL_WEIGHT = '\033[22m' 112 ANSI_NORMAL_WEIGHT = '\033[22m'
98 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)) 113 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))
99 ANSI_BOLD = '\033[1m' 114 ANSI_BOLD = '\033[1m'
100 ANSI_BLINK = '\033[5m' 115 ANSI_BLINK = '\033[5m'