本文整理匯總了Python中logging.config.fileConfig方法的典型用法代碼示例。如果您正苦於以下問題:Python config.fileConfig方法的具體用法?Python config.fileConfig怎麽用?Python config.fileConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類logging.config
的用法示例。
在下文中一共展示了config.fileConfig方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _setup_logging
# 需要導入模塊: from logging import config [as 別名]
# 或者: from logging.config import fileConfig [as 別名]
def _setup_logging(self, config):
log_config_file = config[u'log'][u'config_file']
self._logger.info(u'Logging configuration file: ' + log_config_file)
try:
logging.config.fileConfig(log_config_file)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stderr)
raise PanoptesConfigurationError(
u'Could not instantiate logger with logging configuration provided in file "%s": (%s) %s' % (
log_config_file, exc_type, exc_value))
# Create a filter to rate limit logs so that a misconfiguration or failure does not make the disk I/O go
# beserk or fill up the disk space. We do this in code instead if configuration for two reasons:
# - It enforces a filter on every handler, so no chance of messing them up in configuration
# - We use fileConfig (nof dictConfig) to setup our logging and fileConfig does not support filter configuration
throttle = RateLimitingFilter(rate=config[u'log'][u'rate'], per=config[u'log'][u'per'],
burst=config[u'log'][u'burst'])
# Apply the filter to all handlers. Note that this would be a shared filter across ALL logs generated by this
# process and thus the rate/burst should be set appropriately high
for handler in logging._handlerList:
# _handlerList is a list of weakrefs, so the object returned has to be dereferenced
handler().addFilter(throttle)
示例2: load_configuration
# 需要導入模塊: from logging import config [as 別名]
# 或者: from logging.config import fileConfig [as 別名]
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
示例3: logging_file_config
# 需要導入模塊: from logging import config [as 別名]
# 或者: from logging.config import fileConfig [as 別名]
def logging_file_config(self, config_file):
"""
Setup logging via the logging module's fileConfig function with the
specified ``config_file``, if applicable.
ConfigParser defaults are specified for the special ``__file__``
and ``here`` variables, similar to PasteDeploy config loading.
"""
parser = ConfigParser.ConfigParser()
parser.read([config_file])
if parser.has_section('loggers'):
config_file = os.path.abspath(config_file)
fileConfig(config_file, dict(__file__=config_file,
here=os.path.dirname(config_file)))
示例4: ProvisionLoggers
# 需要導入模塊: from logging import config [as 別名]
# 或者: from logging.config import fileConfig [as 別名]
def ProvisionLoggers(self):
"""Loads Log Handler & Config
Returns:
None: Simple loader, Nothing needed
"""
if self._conf.get('Logging', 'ConfigurationFile'):
if os.path.isfile(self._conf.get('Logging', 'ConfigurationFile')):
config.fileConfig(self._conf.get('Logging', 'ConfigurationFile'))
self._logger = logging.getLogger('GREASE')
else:
self.DefaultLogger()
else:
self.DefaultLogger()
示例5: _use_config_file
# 需要導入模塊: from logging import config [as 別名]
# 或者: from logging.config import fileConfig [as 別名]
def _use_config_file(cls, config_file):
"""Use parsed logging configuration."""
try:
config.fileConfig(cls._PARSER, disable_existing_loggers=False)
LOG.info('Logging config file "%s" loaded successfully.',
config_file)
except OSError:
cls._catch_config_file_exception(config_file)
示例6: setup_logging
# 需要導入模塊: from logging import config [as 別名]
# 或者: from logging.config import fileConfig [as 別名]
def setup_logging():
"""Reads the Storj GUI logging configuration from logging.conf.
If the file does not exist it will load a default configuration.
Mac OS X (POSIX):
~/.storj-gui
Unix (POSIX):
~/.storj-gui
Win XP (not roaming):
``C:\Documents and Settings\<user>\Application Data\storj-gui``
Win 7 (not roaming):
``C:\\Users\<user>\AppData\Local\storj-gui``
"""
logging_conf = os.path.join(
click.get_app_dir(APP_NAME, force_posix=True),
'logging.conf')
if not os.path.exists(logging_conf) or not os.path.isfile(logging_conf):
load_default_logging()
logging.getLogger(__name__).warning('%s logging configuration file does not exist', logging_conf)
return
try:
config.fileConfig(logging_conf, disable_existing_loggers=False)
logging.getLogger(__name__).info('%s configuration file was loaded.', logging_conf)
except RuntimeError:
load_default_logging()
logging.getLogger(__name__).warning('failed to load configuration from %s', logging_conf)
return
logging.getLogger(__name__).info('using logging configuration from %s', logging_conf)