与上一个问题Airbrake logger in Django still sending notifications even though its level is set to 'CRITICAL'?相关,我正在研究一个包含 public class OzoneLiveLite : Ozone_Live_LiteEntities
{
public DbSet<CORP_MASTER> CorpMaster { get; set; }
public DbSet<JCS_FINYEAR> JcsFinyear { get; set; }
public DbSet<JCS_JOB> JcsJob { get; set; }
public DbSet<JCS_JOB__JCS_JOB_SUBJOB> JcsJobJcsJobSubjob { get; set; }
public DbSet<JCS_FINYEAR__JCFY_PERIOD> JcsFinyearJcfyPeriod { get; set; }
}
的多个版本的Django项目:settings.py
,settings/base.py
等。< / p>
还有一种设置'mixin',settings/staging.py
,其中包含以下settings/staging_development.py
配置:
LOGGING
这是# Auxiliary variable used in LOGGING
_AIRBRAKE_LOGGER = {
'handlers': ['airbrake'],
'level': 'ERROR',
'propagate': True,
}
# Airbrake logging integration (cf. https://github.com/airbrake/pybrake#django-integration)
# In our case, 'app' is replaced by three apps, 'lucy_web', 'api', and 'activation'.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'airbrake': {
'level': 'ERROR',
'class': 'pybrake.LoggingHandler',
},
},
'loggers': {
'lucy_web': _AIRBRAKE_LOGGER,
'api': _AIRBRAKE_LOGGER,
'activation': _AIRBRAKE_LOGGER,
},
}
导入的settings/staging.py
进一步LOGGING
d,如下所示:
.update()
我想要实现的是登录Airbrake以及控制台。现在,如果我只是在注释掉的代码中注释并重新定义from lucy.settings.staging_production import *
# LOGGING = {
# 'version': 1,
# 'disable_existing_loggers': False,
# 'handlers': {
# 'console': {
# 'class': 'logging.StreamHandler',
# },
# },
# 'loggers': {
# 'django': {
# 'handlers': ['console'],
# 'level': os.getenv('LOG_LEVEL', 'INFO'),
# },
# },
# }
LOGGING['handlers'].update(console={
'class': 'logging.StreamHandler'
})
LOGGING['loggers'].update(django={
'handlers': ['console'],
'level': os.getenv('LOG_LEVEL', 'INFO'),
})
配置,我会注意到错误消息已成功记录到控制台。但是,如果我按原样使用代码,它们就不会,即使我收到了Airbrake通知。
如果我在shell中浏览,一切看起来都不错:例如,LOGGING
和'lucy_web'
记录器都附加了处理程序,'django'
设置为propagate
:< / p>
True
简而言之,即使启用了日志传播,我也可以获得一种类型的日志记录或其他日志,但不能同时使用两种日志。
知道问题可能是什么?
答案 0 :(得分:0)
我通过将'console'
处理程序添加到应用程序('lucy_web'
,'api'
和'activation'
)本身而不是全部{{{}来解决了这个问题。 3}}记录器。实际上,我认为在问题的根源上,我抛出的错误不在'django'
记录器的层次结构中。
首先,在settings/base.py
我使用deepcopy
:
from copy import deepcopy
# Auxiliary variable used in LOGGING
_AIRBRAKE_LOGGER = {
'handlers': ['airbrake'],
'level': 'ERROR',
'propagate': True,
}
# Airbrake logging integration (cf. https://github.com/airbrake/pybrake#django-integration)
# In our case, 'app' is replaced by three apps, 'lucy_web', 'api', and 'activation'.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'airbrake': {
'level': 'ERROR',
'class': 'pybrake.LoggingHandler',
},
},
'loggers': {
# The deepcopy allows us to append to each app's 'handlers' list without affecting the others
'lucy_web': deepcopy(_AIRBRAKE_LOGGER),
'api': deepcopy(_AIRBRAKE_LOGGER),
'activation': deepcopy(_AIRBRAKE_LOGGER),
},
}
其次,在settings/staging.py
我更新了LOGGING
,如此:
LOGGING['handlers'].update(console={
'class': 'logging.StreamHandler'
})
for app in ('lucy_web', 'api', 'activation'):
LOGGING['loggers'][app]['handlers'].append('console')
现在错误会记录到Airbrake和控制台。