def get_server_list(config): if isinstance(config, list): return ','.join(["%s:%s" % (c['host'], c['port']) for c in config]) elif config.has_key('server_list'): return ','.join( ["%s:%s" % (c['host'], c['port']) for c in config['server_list']]) elif config.has_key('zookeeper'): return ','.join(config['zookeeper']['server_list']) elif config.has_key('header'): return "%s:%s" % (config['host'], config['port'])
def reconfigure(config): """ Setup logging configuration from the logging section provided in the night-watch.yml config file. This function is called after night-watch.yml config file has been read, providing the logging config section as a Python dictionary. Note: the logging section must be a dictionary parsable by the logging.dictConfig() function (see https://docs.python.org/2/library/logging.config.html#logging-config-dict-connections). """ if config: # For each handlers using files, check if the folder used exists. If not, try to create the folder(s) # (in the case the folder couldn't be created, the config can't be loaded and the default logger is kept) if config.has_key('handlers'): for handler_name, handler_config in config['handlers'].iteritems(): if handler_config.has_key('filename'): try: # if the folder which will contain the log file don't exists, create it path_log_file = os.path.dirname(handler_config['filename']) if path_log_file != '' and not os.path.exists(path_log_file): os.makedirs(path_log_file, 700) except Exception: logging.getLogger().error('Unable to access/create log folder ' + path_log_file + ' for handler ' + handler_name + ', continue with default logger', exc_info=True) return try: # Load the log configuration logging.config.dictConfig(config) logging.getLogger(__name__).info('Logging config successfully loaded') except Exception: logging.getLogger().error('Unable to load the logging configuration, continue with default logger.\n' \ 'Please check logging section of night-watch.yml config file.\n' \ 'The logging section must be a dictionary parsable by the logging.dictConfig() function (see https://docs.python.org/2/library/logging.config.html#logging-config-dict-connections)', exc_info=True) return else: # config section not defined logging.getLogger().info('No logging section defined in night-watch.yml config file, continue with default logger')
def update(self, config): filename = None if isinstance(config, basestring): filename = config config = _Parser().dict_from_file(config) elif isinstance(config, dict): config = config.copy() dict.update(self, config) if filename and config.has_key('loggers'): logging.config.fileConfig(filename)
def reconfigure(config): """ Setup logging configuration from the logging section provided in the night-watch.yml config file. This function is called after night-watch.yml config file has been read, providing the logging config section as a Python dictionary. Note: the logging section must be a dictionary parsable by the logging.dictConfig() function (see https://docs.python.org/2/library/logging.config.html#logging-config-dict-connections). """ if config: # For each handlers using files, check if the folder used exists. If not, try to create the folder(s) # (in the case the folder couldn't be created, the config can't be loaded and the default logger is kept) if config.has_key('handlers'): for handler_name, handler_config in config['handlers'].iteritems(): if handler_config.has_key('filename'): try: # if the folder which will contain the log file don't exists, create it path_log_file = os.path.dirname( handler_config['filename']) if path_log_file != '' and not os.path.exists( path_log_file): os.makedirs(path_log_file, 700) except Exception: logging.getLogger().error( 'Unable to access/create log folder ' + path_log_file + ' for handler ' + handler_name + ', continue with default logger', exc_info=True) return try: # Load the log configuration logging.config.dictConfig(config) logging.getLogger(__name__).info( 'Logging config successfully loaded') except Exception: logging.getLogger().error('Unable to load the logging configuration, continue with default logger.\n' \ 'Please check logging section of night-watch.yml config file.\n' \ 'The logging section must be a dictionary parsable by the logging.dictConfig() function (see https://docs.python.org/2/library/logging.config.html#logging-config-dict-connections)', exc_info=True) return else: # config section not defined logging.getLogger().info( 'No logging section defined in night-watch.yml config file, continue with default logger' )
libPath = basePath + '/lib' sys.path.insert(1, libPath) import raw_wsgi as wsgi from core.application import Application from core.wsgi import Request import logging import logging.config # [Load Server Configuration] # import conf.server config = conf.server.Config if not config.has_key('basePath'): config['basePath'] = basePath # [Init The Logger] # logging.config.fileConfig(basePath + '/conf/log.cfg') logger = logging.getLogger() # [Config the core] # import core.instrument if config.get('debug') == True: logger.setLevel(logging.DEBUG) signal.signal(signal.SIGUSR1, core.instrument.dumpOnSignal) else: logger.setLevel(config.get('logLevel', logging.INFO))
def setup_default_logging(level, to_console): """ Default logging config. Required Arguments: level The log level to use (['INFO', 'WARN', 'ERROR', 'DEBUG', 'FATAL']) to_console Whether to setup console logging or not. """ config = namespaces['root'].config all_levels = ['INFO', 'WARN', 'ERROR', 'DEBUG', 'FATAL'] # Log level if config.has_key('debug') and config['debug']: level = 'DEBUG' elif level and level.upper() in all_levels: level = level elif config.has_key('log_level'): level = config['log_level'] else: level = 'INFO' app_log = logging.getLogger(config['app_module']) cement_log = logging.getLogger('cement') log_level = getattr(logging, level.upper()) app_log.setLevel(log_level) cement_log.setLevel(log_level) # Console formatter if to_console: console = logging.StreamHandler() if log_level == logging.DEBUG: console.setFormatter( logging.Formatter( "%(asctime)s (%(levelname)s) %(name)s : %(message)s")) else: console.setFormatter( logging.Formatter("%(levelname)s: %(message)s")) console.setLevel(log_level) app_log.addHandler(console) cement_log.addHandler(console) # File formatter if config.has_key('log_file'): if config.has_key('log_max_bytes'): from logging.handlers import RotatingFileHandler if not config.has_key('log_max_files'): config['log_max_files'] = 4 file_handler = RotatingFileHandler( config['log_file'], maxBytes=int(config['log_max_bytes']), backupCount=int(config['log_max_files'])) else: from logging import FileHandler file_handler = FileHandler(config['log_file']) file_handler.setFormatter( logging.Formatter( "%(asctime)s (%(levelname)s) %(name)s : %(message)s")) file_handler.setLevel(log_level) app_log.addHandler(file_handler) cement_log.addHandler(file_handler)
libPath = basePath+'/lib' sys.path.insert(1,libPath) import raw_wsgi as wsgi from core.application import Application from core.wsgi import Request import logging import logging.config # [Load Server Configuration] # import conf.server config = conf.server.Config; if not config.has_key('basePath'): config['basePath'] = basePath # [Init The Logger] # logging.config.fileConfig(basePath+'/conf/log.cfg') logger = logging.getLogger() # [Config the core] # import core.instrument if config.get('debug')==True: logger.setLevel(logging.DEBUG) signal.signal(signal.SIGUSR1, core.instrument.dumpOnSignal) else: logger.setLevel(config.get('logLevel', logging.INFO))
def setup_default_logging(level, to_console): """ Default logging config. Required Arguments: level The log level to use (['INFO', 'WARN', 'ERROR', 'DEBUG', 'FATAL']) to_console Whether to setup console logging or not. """ config = namespaces['root'].config all_levels = ['INFO', 'WARN', 'ERROR', 'DEBUG', 'FATAL'] # Log level if config.has_key('debug') and config['debug']: level = 'DEBUG' elif level and level.upper() in all_levels: level = level elif config.has_key('log_level'): level = config['log_level'] else: level = 'INFO' app_log = logging.getLogger(config['app_module']) cement_log = logging.getLogger('cement') log_level = getattr(logging, level.upper()) app_log.setLevel(log_level) cement_log.setLevel(log_level) # Console formatter if to_console: console = logging.StreamHandler() if log_level == logging.DEBUG: console.setFormatter(logging.Formatter( "%(asctime)s (%(levelname)s) %(name)s : %(message)s")) else: console.setFormatter( logging.Formatter("%(levelname)s: %(message)s") ) console.setLevel(log_level) app_log.addHandler(console) cement_log.addHandler(console) # File formatter if config.has_key('log_file'): if config.has_key('log_max_bytes'): from logging.handlers import RotatingFileHandler if not config.has_key('log_max_files'): config['log_max_files'] = 4 file_handler = RotatingFileHandler( config['log_file'], maxBytes=int(config['log_max_bytes']), backupCount=int(config['log_max_files']) ) else: from logging import FileHandler file_handler = FileHandler(config['log_file']) file_handler.setFormatter( logging.Formatter("%(asctime)s (%(levelname)s) %(name)s : %(message)s") ) file_handler.setLevel(log_level) app_log.addHandler(file_handler) cement_log.addHandler(file_handler)