當前位置: 首頁>>代碼示例>>Python>>正文


Python settings.LOGGING屬性代碼示例

本文整理匯總了Python中django.conf.settings.LOGGING屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.LOGGING屬性的具體用法?Python settings.LOGGING怎麽用?Python settings.LOGGING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.conf.settings的用法示例。


在下文中一共展示了settings.LOGGING屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def setup(set_prefix=True):
    """
    Configure the settings (this happens as a side effect of accessing the
    first setting), configure logging and populate the app registry.
    Set the thread-local urlresolvers script prefix if `set_prefix` is True.
    """
    from django.apps import apps
    from django.conf import settings
    from django.urls import set_script_prefix
    from django.utils.log import configure_logging

    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
    if set_prefix:
        set_script_prefix(
            '/' if settings.FORCE_SCRIPT_NAME is None else settings.FORCE_SCRIPT_NAME
        )
    apps.populate(settings.INSTALLED_APPS) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:19,代碼來源:__init__.py

示例2: get_string_db_logger

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def get_string_db_logger():
    """
    Gets you what you need to log to a string. Returns a pair of StringIO, logger variables.
    >>> output, logger = get_string_db_logger()
    >>> call_stuff_to_debug_with_logger(logger=logger)
    >>> print output.getvalue()
    """
    logger = logging.getLogger('django.db.backends')
    logger.setLevel(logging.DEBUG)
    try:
        fmt = settings.LOGGING['formatters']['verbose']['format']
    except KeyError:
        fmt = "%(levelname)-7s %(asctime)s | %(message)s"
    formatter = logging.Formatter(fmt)
    output = StringIO()
    string_handler = logging.StreamHandler(output)
    string_handler.setFormatter(formatter)
    string_handler.setLevel(logging.DEBUG)
    logger.addHandler(string_handler)

    return output, logger 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:23,代碼來源:decorators.py

示例3: setup

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def setup(set_prefix=True):
    """
    Configure the settings (this happens as a side effect of accessing the
    first setting), configure logging and populate the app registry.
    Set the thread-local urlresolvers script prefix if `set_prefix` is True.
    """
    from django.apps import apps
    from django.conf import settings
    from django.urls import set_script_prefix
    from django.utils.encoding import force_text
    from django.utils.log import configure_logging

    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
    if set_prefix:
        set_script_prefix(
            '/' if settings.FORCE_SCRIPT_NAME is None else force_text(settings.FORCE_SCRIPT_NAME)
        )
    apps.populate(settings.INSTALLED_APPS) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:20,代碼來源:__init__.py

示例4: handle

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def handle(self, *args, **options):
    with Mainframe() as mainframe:
      uname = platform.uname()
      with open(settings.LOGGING['handlers']['file']['filename'], 'r') as log:
        traceback = self.tail(log, 100)

      payload = {
          'path': sys.path,
          'version': platform.python_version(),
          'system': {x: uname.__getattribute__(x) for x in uname._fields},
          'distro': '-'.join(platform.linux_distribution()),
          'log': traceback,
          'directory': settings.BASE_DIR
      }
      response = requests.put("https://{}/api/v1/instance/{}/report".format(
                              settings.MAINFRAME, mainframe().id),
                              json=payload)

      identifier = response.json()['result']['id']

      self.stdout.write(self.style.SUCCESS("""
        When talking to the maintainer indietyp,
        please use this ID to identify your ticket:"""))
      self.stdout.write(identifier) 
開發者ID:indietyp,項目名稱:hawthorne,代碼行數:26,代碼來源:report.py

示例5: setUp

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def setUp(self):
        logging_conf = """
[loggers]
keys=root
[handlers]
keys=stream
[formatters]
keys=simple
[logger_root]
handlers=stream
[handler_stream]
class=StreamHandler
formatter=simple
args=(sys.stdout,)
[formatter_simple]
format=%(message)s
"""
        self.temp_file = NamedTemporaryFile()
        self.temp_file.write(logging_conf.encode())
        self.temp_file.flush()
        sdict = {'LOGGING_CONFIG': '"logging.config.fileConfig"',
                 'LOGGING': 'r"%s"' % self.temp_file.name}
        self.write_settings('settings.py', sdict=sdict) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:25,代碼來源:tests.py

示例6: setup

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def setup():
    """
    Configure the settings (this happens as a side effect of accessing the
    first setting), configure logging and populate the app registry.
    """
    from django.apps import apps
    from django.conf import settings
    from django.utils.log import configure_logging

    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
    apps.populate(settings.INSTALLED_APPS) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:13,代碼來源:__init__.py

示例7: configure_logger

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def configure_logger(conf=None, **kwargs):
    from django.conf import settings
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) 
開發者ID:007gzs,項目名稱:dingtalk-django-example,代碼行數:5,代碼來源:celery.py

示例8: get_warn_log

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def get_warn_log(request):
    warn_log_file = settings.LOGGING['handlers']['my_warn']['filename']
    logs = list(reversed(open(warn_log_file).read().split('\n')))[:500]

    logs = [l for l in logs if l]

    context = dict()
    context['logs'] = logs

    return render(request, 'dashboard/logs.html', context=context) 
開發者ID:richshaw2015,項目名稱:oh-my-rss,代碼行數:12,代碼來源:views_dash.py

示例9: config_loggers

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def config_loggers(*args, **kwargs):
    dictConfig(settings.LOGGING) 
開發者ID:openwisp,項目名稱:ansible-openwisp2,代碼行數:4,代碼來源:celery.py

示例10: config_loggers

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def config_loggers(*args, **kwags):
    dictConfig(settings.LOGGING)

# example task that is passed info about itself 
開發者ID:FNNDSC,項目名稱:ChRIS_ultron_backEnd,代碼行數:6,代碼來源:celery.py

示例11: setUpClass

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def setUpClass(cls):
        super().setUpClass()
        cls._logging = settings.LOGGING
        logging.config.dictConfig(DEFAULT_LOGGING) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例12: setUp

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def setUp(self):
        log_config = """{
    'version': 1,
    'handlers': {
        'custom_handler': {
            'level': 'INFO',
            'class': 'logging_tests.logconfig.MyHandler',
        }
    }
}"""
        self.write_settings('settings.py', sdict={'LOGGING': log_config}) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:13,代碼來源:tests.py

示例13: reload_django_settings

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
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) 
開發者ID:jpush,項目名稱:jbox,代碼行數:62,代碼來源:django_wsgi.py

示例14: reset_loggers_level

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LOGGING [as 別名]
def reset_loggers_level():
    """
    Reset loggers' level from AppVar
    """

    def getEffectiveLevel(self):
        """
        Get the effective level for this logger.

        Loop through this logger and its parents in the logger hierarchy,
        looking for a non-zero logging level. Return the first one found.
        """
        logger = self

        # custom logic
        # cannot use AppVar due to circular import issue
        app_var_level = redis.pop(f'app_var:Logging:logger:{logger.name}:log_level')
        if app_var_level:
            app_var_level = app_var_level.upper()
            if app_var_level in logging._levelToName.values():
                logger.setLevel(app_var_level)

                # log sql to console
                if logger.name == 'django.db.backends':
                    handler = logging.StreamHandler()
                    handler.setLevel(logger.level)
                    logger_handler_classes = [i.__class__ for i in logger.handlers]
                    if redis.pop(f'app_var:Logging:logger:{logger.name}:log_to_console') is True:
                        if handler.__class__ not in logger_handler_classes:
                            logger.addHandler(handler)
                    else:
                        logger.handlers = [i for i in logger.handlers if i.__class__ != handler.__class__]
        # end custom logic

        while logger:
            if logger.level:
                return logger.level
            logger = logger.parent
        return logging.NOTSET

    # reset Project loggers
    for logger_name in settings.LOGGING['loggers']:
        logger = logging.getLogger(logger_name)
        logger.getEffectiveLevel = types.MethodType(getEffectiveLevel, logger)

    # reset celery loggers
    for logger_name in celery_logger_names:
        logger = get_logger(logger_name)
        logger.getEffectiveLevel = types.MethodType(getEffectiveLevel, logger) 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:51,代碼來源:app_vars.py


注:本文中的django.conf.settings.LOGGING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。