Python logging.conf() Examples
The following are 8
code examples of logging.conf().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
logging
, or try the search function
.
Example #1
Source File: base_app.py From mars with Apache License 2.0 | 6 votes |
def __call__(self, argv=None): import json if argv is None: argv = sys.argv[1:] new_argv = [] for a in argv: if not a.startswith('-D'): new_argv.append(a) continue conf, val = a[2:].split('=', 1) conf_parts = conf.split('.') conf_obj = options for g in conf_parts[:-1]: conf_obj = getattr(conf_obj, g) try: setattr(conf_obj, conf_parts[-1], json.loads(val)) except: # noqa: E722 setattr(conf_obj, conf_parts[-1], val) return self._main(new_argv)
Example #2
Source File: base_app.py From mars with Apache License 2.0 | 6 votes |
def config_logging(self): import logging.config import mars log_conf = self.args.log_conf or 'logging.conf' conf_file_paths = [ '', os.path.abspath('.'), os.path.dirname(os.path.dirname(mars.__file__)) ] log_configured = False for path in conf_file_paths: conf_path = os.path.join(path, log_conf) if path else log_conf if os.path.exists(conf_path): logging.config.fileConfig(conf_path, disable_existing_loggers=False) log_configured = True break if not log_configured: log_level = self.args.log_level or self.args.level log_format = self.args.log_format or self.args.format level = getattr(logging, log_level.upper()) if log_level else logging.INFO logging.getLogger('mars').setLevel(level) logging.basicConfig(format=log_format)
Example #3
Source File: config.py From oneview-redfish-toolkit with Apache License 2.0 | 6 votes |
def load_conf_file(conf_file): """Loads and parses conf file Loads and parses the module conf file Args: conf_file: string with the conf file name Returns: ConfigParser object with conf_file configs """ if not os.path.isfile(conf_file): raise OneViewRedfishResourceNotFoundException( "File {} not found.".format(conf_file) ) config = configparser.ConfigParser() config.optionxform = str try: config.read(conf_file) except Exception: raise return config
Example #4
Source File: log_config.py From storj-python-sdk with MIT License | 6 votes |
def load_configuration(config_file=DEFAULT_CONFIG_FILE): """ Loads logging configuration from the given configuration file. :param config_file: the configuration file (default=/etc/package/logging.conf) :type config_file: str """ if not os.path.exists(config_file) or not os.path.isfile(config_file): msg = '%s configuration file does not exist!', config_file logging.getLogger(__name__).error(msg) raise ValueError(msg) try: config.fileConfig(config_file, disable_existing_loggers=False) logging.getLogger(__name__).info( '%s configuration file was loaded.', config_file) except Exception as e: logging.getLogger(__name__).error( 'Failed to load configuration from %s!', config_file) logging.getLogger(__name__).debug(str(e), exc_info=True) raise e
Example #5
Source File: config.py From oneview-redfish-toolkit with Apache License 2.0 | 5 votes |
def auth_mode_is_conf(): return get_authentication_mode() == 'conf'
Example #6
Source File: config.py From oneview-redfish-toolkit with Apache License 2.0 | 5 votes |
def configure_logging(log_file_path): """Loads logging.conf file Loads logging.conf file to create the logger configuration. The logger configuration has two handlers, one of stream (show logs in the console) and other of file (save a log file) where you can choose one of it in [logger_root : handlers]. In it you can choose the logger level as well. Level: Numeric value --------------------- CRITICAL: 50 ERROR: 40 WARNING: 30 INFO: 20 DEBUG: 10 NOTSET: 00 --------------------- How to use: import logging and logging.exception('message') Args: log_file_path: logging.conf path. Exception: Exception: if logging.conf file not found. """ if os.path.isfile(log_file_path) is False: raise Exception("Config file {} not found".format(log_file_path)) else: logging.config.fileConfig(log_file_path)
Example #7
Source File: im_service.py From im with GNU General Public License v3.0 | 4 votes |
def config_logging(): """ Init the logging info """ try: # First look at /etc/im/logging.conf file logging.config.fileConfig('/etc/im/logging.conf') except Exception as ex: print(ex) log_dir = os.path.dirname(Config.LOG_FILE) if not os.path.isdir(log_dir): os.makedirs(log_dir) fileh = logging.handlers.RotatingFileHandler( filename=Config.LOG_FILE, maxBytes=Config.LOG_FILE_MAX_SIZE, backupCount=3) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fileh.setFormatter(formatter) if Config.LOG_LEVEL == "DEBUG": log_level = logging.DEBUG elif Config.LOG_LEVEL == "INFO": log_level = logging.INFO elif Config.LOG_LEVEL in ["WARN", "WARNING"]: log_level = logging.WARN elif Config.LOG_LEVEL == "ERROR": log_level = logging.ERROR elif Config.LOG_LEVEL in ["FATAL", "CRITICAL"]: log_level = logging.FATAL else: log_level = logging.WARN logging.RootLogger.propagate = 0 logging.root.setLevel(logging.ERROR) log = logging.getLogger('ConfManager') log.setLevel(log_level) log.propagate = 0 log.addHandler(fileh) log = logging.getLogger('CloudConnector') log.setLevel(log_level) log.propagate = 0 log.addHandler(fileh) log = logging.getLogger('InfrastructureManager') log.setLevel(log_level) log.propagate = 0 log.addHandler(fileh) # Add the filter to add extra fields try: filt = ExtraInfoFilter() log = logging.getLogger('ConfManager') log.addFilter(filt) log = logging.getLogger('CloudConnector') log.addFilter(filt) log = logging.getLogger('InfrastructureManager') log.addFilter(filt) except Exception as ex: print(ex)
Example #8
Source File: config.py From oneview-redfish-toolkit with Apache License 2.0 | 4 votes |
def load_config(conf_file): """Loads redfish.conf file Loads and parsers the system conf file into config global var Loads json schemas into schemas_dict global var Established a connection with OneView and sets in as ov_conn global var Args: conf_file: string with the conf file name Returns: None Exception: HPOneViewException: - if fails to connect to oneview """ config = load_conf_file(conf_file) globals()['config'] = config # Config file read set global vars # Setting ov_config # ov_config = dict(config.items('oneview_config')) # ov_config['credentials'] = dict(config.items('credentials')) # ov_config['api_version'] = API_VERSION # globals()['ov_config'] = ov_config util.load_event_service_info() # Load schemas | Store schemas try: for ip_oneview in get_oneview_multiple_ips(): connection.check_oneview_availability(ip_oneview) registry_dict = load_registry( get_registry_path(), schemas.REGISTRY) globals()['registry_dict'] = registry_dict load_schemas(get_schemas_path()) except Exception as e: raise OneViewRedfishException( 'Failed to connect to OneView: {}'.format(e) )