我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用django.conf.settings.LOGGING。
def setup_logging(debug=False): """ Configures logging in cases where a Django environment is not supposed to be configured. TODO: This is really confusing, importing django settings is allowed to fail when debug=False, but if it's true it can fail? """ try: from django.conf.settings import LOGGING except ImportError: from kolibri.deployment.default.settings.base import LOGGING if debug: from django.conf import settings settings.DEBUG = True LOGGING['handlers']['console']['level'] = 'DEBUG' LOGGING['loggers']['kolibri']['level'] = 'DEBUG' logger.debug("Debug mode is on!") logging.config.dictConfig(LOGGING)
def try_init_logger(): try: from django.conf import settings setting_keys = dir(settings) if 'LOGGER_CONFIG' in setting_keys: init_logger(**settings.LOGGER_CONFIG) elif 'LOGGING' in setting_keys and settings.LOGGING: import logging global log log = logging.getLogger('main') log.exception = append_exc(log.error) log.data = logging.getLogger('data').info else: init_logger() except: try: import config init_logger(**config.LOGGER_CONFIG) except: try: init_logger() except: pass
def __enter__(self): from .daemon.utils import get_socket_addr logging_config = settings.LOGGING logging_config.update({ 'handlers': { 'console': { 'level': 'DEBUG', 'class': 'borgcube.utils.DaemonLogHandler', 'formatter': 'standard', 'addr_or_socket': 'ipc://' + get_socket_addr('daemon'), }, }, 'formatters': { 'standard': { 'format': '%(message)s' }, }, }) logging.config.dictConfig(logging_config)
def check_sentry_config(app_configs, **kwargs): issues = [] if 'sentry' not in settings.LOGGING['handlers']: return issues if 'sentry' not in settings.LOGGING['loggers']['']['handlers']: issues.append( Warning( "Sentry logging handler is present but unused", hint="Ensure that sentry handler is part of LOGGING['loggers']['']['handlers']", id='tg_utils.W011', ) ) return issues
def train(nn_id, wf_ver) : log_home = "/root" _celery_log_dir = make_celery_dir_by_datetime(log_home) celery_log_dir = make_and_exist_directory(_celery_log_dir) celery_log_file = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') _filename = str(nn_id) +"_" +str(wf_ver) +"_" + celery_log_file + ".log" celery_log_file = celery_log_dir + _filename logging.config.dictConfig(settings.LOGGING) logger = logging.getLogger() task_handler = FileHandler(celery_log_file) logger.addHandler(task_handler) logging.info("=============================================================") logging.info("[Train Task] Start Celery Job {0} {1}".format(nn_id, wf_ver)) logging.info("=============================================================") result = WorkFlowTrainTask()._exec_train(nn_id, wf_ver) logging.info("=============================================================") logging.info("[Train Task] Done Celery Job {0} {1} : {2}".format(nn_id, wf_ver, result)) logging.info("=============================================================") return result
def reload_django_settings(): mod = util.import_module(os.environ['DJANGO_SETTINGS_MODULE']) # Reload module. reload(mod) # Reload settings. # Use code from django.settings.Settings module. # Settings that should be converted into tuples if they're mistakenly entered # as strings. tuple_settings = ("INSTALLED_APPS", "TEMPLATE_DIRS") for setting in dir(mod): if setting == setting.upper(): setting_value = getattr(mod, setting) if setting in tuple_settings and type(setting_value) == str: setting_value = (setting_value,) # In case the user forgot the comma. setattr(settings, setting, setting_value) # Expand entries in INSTALLED_APPS like "django.contrib.*" to a list # of all those apps. new_installed_apps = [] for app in settings.INSTALLED_APPS: if app.endswith('.*'): app_mod = util.import_module(app[:-2]) appdir = os.path.dirname(app_mod.__file__) app_subdirs = os.listdir(appdir) name_pattern = re.compile(r'[a-zA-Z]\w*') for d in sorted(app_subdirs): if (name_pattern.match(d) and os.path.isdir(os.path.join(appdir, d))): new_installed_apps.append('%s.%s' % (app[:-2], d)) else: new_installed_apps.append(app) setattr(settings, "INSTALLED_APPS", new_installed_apps) if hasattr(time, 'tzset') and settings.TIME_ZONE: # When we can, attempt to validate the timezone. If we can't find # this file, no check happens and it's harmless. zoneinfo_root = '/usr/share/zoneinfo' if (os.path.exists(zoneinfo_root) and not os.path.exists(os.path.join(zoneinfo_root, *(settings.TIME_ZONE.split('/'))))): raise ValueError("Incorrect timezone setting: %s" % settings.TIME_ZONE) # Move the time zone info into os.environ. See ticket #2315 for why # we don't do this unconditionally (breaks Windows). os.environ['TZ'] = settings.TIME_ZONE time.tzset() # Settings are configured, so we can set up the logger if required if getattr(settings, 'LOGGING_CONFIG', False): # First find the logging configuration function ... logging_config_path, logging_config_func_name = settings.LOGGING_CONFIG.rsplit('.', 1) logging_config_module = util.import_module(logging_config_path) logging_config_func = getattr(logging_config_module, logging_config_func_name) # ... then invoke it with the logging settings logging_config_func(settings.LOGGING)