更改日志级别

时间:2013-05-09 06:23:07

标签: python django logging python-2.7 django-models

我已在WARNplatform_settings.py文件中将日志级别设置为loggings.py

我还使用WARNforms.py中的初始值更改为(self.fields['log_level'].initial='WARN')

现在,如果我将值从WARN更改为INFOCRITICAL,我希望它在UI中反映,而不是每次都设置[log_level.initial]。我将如何进行更改?

platform_settings.py

for l in loggers:
    logger = logging.getLogger(l)
    logger.setLevel(level)

logging.py

LOGGING = {
  'version': 1,
  'disable_existing_loggers': True,

  'formatters': {
     'cloudos_format': {
        'format': '%(filename)s [(process)d-%(thread)d-%(clientip)s]%(module)s.%(funcName)s:%(message)s'
            },
   },

   'handlers': {
     'null': {
      'level': 'WARN',
      'class': 'django.utils.log.NullHandler',
     },

forms.py

choices = [ ('WARN', 'Warning'),
            ('ERROR', 'Error'),
            ('CRITICAL', 'Critical'),
            ('INFO', 'Info'),
            ('DEBUG', 'Debug') ]
self.fields['log_level'].choices = choices
# self.fields['log_level'].initial='WARN'

cache_val = cloudos_cache.get('all_users', 'log_level')
if cache_val:
   self.fields['log_level'].initial = cache_val
else:
   logger = logging.getLogger('skyline')
   Lev=logging.getLevelName(level)
   logger.setLevel(Lev)

0 个答案:

没有答案