mirror of
https://github.com/datafolklabs/cement.git
synced 2026-02-06 11:56:51 +00:00
Deprecate FATAL Logging Facility in Favor of CRITICAL
- Resolves Issue #533
This commit is contained in:
parent
18fdae4ed0
commit
861aed7dcb
@ -29,7 +29,8 @@ Misc:
|
||||
|
||||
Deprecations:
|
||||
|
||||
- None
|
||||
- `[ext.logging]` Deprecate FATAL facility in favor of CRITICAL.
|
||||
- [Issue #533](https://github.com/datafolklabs/cement/issues/533)
|
||||
|
||||
|
||||
## 3.0.8 - Aug 18, 2022
|
||||
|
||||
@ -4,6 +4,7 @@ from warnings import warn
|
||||
DEPRECATIONS = {
|
||||
'3.0.8-1': "Environment variable CEMENT_FRAMEWORK_LOGGING is deprecated in favor of CEMENT_LOG, and will be removed in Cement v3.2.0", # noqa: E501
|
||||
'3.0.8-2': "App.Meta.framework_logging will be changed or removed in Cement v3.2.0", # noqa: E501
|
||||
'3.0.10-1': "The FATAL logging facility is deprecated in favor of CRITICAL, and will be removed in future versions of Cement.", # noqa: E501
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ Cement logging extension module.
|
||||
import os
|
||||
import logging
|
||||
from ..core import log
|
||||
from ..core.deprecations import deprecate
|
||||
from ..utils.misc import is_true, minimal_logger
|
||||
from ..utils import fs
|
||||
|
||||
@ -92,7 +93,7 @@ class LoggingLogHandler(log.LogHandler):
|
||||
#: The help description for the log level argument
|
||||
log_level_argument_help = 'logging level'
|
||||
|
||||
levels = ['INFO', 'WARNING', 'ERROR', 'DEBUG', 'FATAL']
|
||||
levels = ['INFO', 'WARNING', 'ERROR', 'DEBUG', 'FATAL', 'CRITICAL']
|
||||
|
||||
def __init__(self, *args, **kw):
|
||||
super(LoggingLogHandler, self).__init__(*args, **kw)
|
||||
@ -120,7 +121,10 @@ class LoggingLogHandler(log.LogHandler):
|
||||
"""
|
||||
Set the log level. Must be one of the log levels configured in
|
||||
self.levels which are
|
||||
``['INFO', 'WARNING', 'ERROR', 'DEBUG', 'FATAL']``.
|
||||
``['INFO', 'WARNING', 'ERROR', 'DEBUG', 'FATAL', 'CRITICAL]``.
|
||||
|
||||
As of Cement 3.0.10, the FATAL facility is deprecated and will be
|
||||
removed in future versions of Cement. Please us `CRITICAL` instead.
|
||||
|
||||
:param level: The log level to set.
|
||||
|
||||
@ -130,8 +134,13 @@ class LoggingLogHandler(log.LogHandler):
|
||||
self.clear_loggers(namespace)
|
||||
|
||||
level = level.upper()
|
||||
|
||||
if level not in self.levels:
|
||||
level = 'INFO'
|
||||
|
||||
if level == 'FATAL':
|
||||
deprecate('3.0.10-1')
|
||||
|
||||
level = getattr(logging, level.upper())
|
||||
|
||||
self.backend.setLevel(level)
|
||||
@ -311,9 +320,9 @@ class LoggingLogHandler(log.LogHandler):
|
||||
kwargs = self._get_logging_kwargs(namespace, **kw)
|
||||
self.backend.error(msg, **kwargs)
|
||||
|
||||
def fatal(self, msg, namespace=None, **kw):
|
||||
def critical(self, msg, namespace=None, **kw):
|
||||
"""
|
||||
Log to the FATAL (aka CRITICAL) facility.
|
||||
Log to the CRITICAL facility.
|
||||
|
||||
Args:
|
||||
msg (str): The message to log.
|
||||
@ -329,6 +338,30 @@ class LoggingLogHandler(log.LogHandler):
|
||||
|
||||
"""
|
||||
kwargs = self._get_logging_kwargs(namespace, **kw)
|
||||
self.backend.critical(msg, **kwargs)
|
||||
|
||||
def fatal(self, msg, namespace=None, **kw):
|
||||
"""
|
||||
Log to the FATAL (aka CRITICAL) facility.
|
||||
|
||||
As of Cement 3.0.10, this method is deprecated and will be removed in
|
||||
future versions of Cement. Please us `critical()` instead.
|
||||
|
||||
Args:
|
||||
msg (str): The message to log.
|
||||
|
||||
Keyword Args:
|
||||
namespace (str): A log prefix, generally the module ``__name__``
|
||||
that the log is coming from. Will default to
|
||||
``self._meta.namespace`` if none is passed.
|
||||
|
||||
Other Parameters:
|
||||
kwargs: Keyword arguments are passed on to the backend logging
|
||||
system.
|
||||
|
||||
"""
|
||||
deprecate('3.0.10-1')
|
||||
kwargs = self._get_logging_kwargs(namespace, **kw)
|
||||
self.backend.fatal(msg, **kwargs)
|
||||
|
||||
def debug(self, msg, namespace=None, **kw):
|
||||
|
||||
@ -23,3 +23,9 @@ class TestDeprecations(object):
|
||||
app.run()
|
||||
assert "3.0.8-2" in str(w[-1].message)
|
||||
sys.argv = orig_argv
|
||||
|
||||
def test_3_0_10__1(self):
|
||||
with TestApp() as app:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
app.log.set_level('FATAL')
|
||||
assert "3.0.10-1" in str(w[-1].message)
|
||||
|
||||
@ -28,18 +28,21 @@ def test_alternate_namespaces(tmp):
|
||||
app.log.info('TEST', extra=dict(namespace=__name__))
|
||||
app.log.warning('TEST', extra=dict(namespace=__name__))
|
||||
app.log.error('TEST', extra=dict(namespace=__name__))
|
||||
app.log.critical('TEST', extra=dict(namespace=__name__))
|
||||
app.log.fatal('TEST', extra=dict(namespace=__name__))
|
||||
app.log.debug('TEST', extra=dict(namespace=__name__))
|
||||
|
||||
app.log.info('TEST', __name__, extra=dict(foo='bar'))
|
||||
app.log.warning('TEST', __name__, extra=dict(foo='bar'))
|
||||
app.log.error('TEST', __name__, extra=dict(foo='bar'))
|
||||
app.log.critical('TEST', __name__, extra=dict(foo='bar'))
|
||||
app.log.fatal('TEST', __name__, extra=dict(foo='bar'))
|
||||
app.log.debug('TEST', __name__, extra=dict(foo='bar'))
|
||||
|
||||
app.log.info('TEST', __name__)
|
||||
app.log.warning('TEST', __name__)
|
||||
app.log.error('TEST', __name__)
|
||||
app.log.critical('TEST', __name__)
|
||||
app.log.fatal('TEST', __name__)
|
||||
app.log.debug('TEST', __name__)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user