Deprecate calling run without a logging config.

This commit is contained in:
Dave Shawley 2019-09-03 07:29:20 -04:00
parent b7b787ee31
commit e6ef43c050
4 changed files with 51 additions and 5 deletions

View file

@ -7,6 +7,8 @@ Release History
---------------
- Make shutdown timings configurable.
- Add :class:`sprockets.http.testing.SprocketsHttpTestCase`.
- Deprecate calling :func:`sprockets.http.run` without a specified
logging configuration.
`2.0.1`_ (5 Mar 2019)
----------------------

View file

@ -1,6 +1,7 @@
from tornado import web
from sprockets.http import app, mixins, run
from sprockets.http import app, mixins
import sprockets.http
class StatusHandler(mixins.ErrorLogger, mixins.ErrorWriter,
@ -37,4 +38,27 @@ class Application(app.Application):
if __name__ == '__main__':
run(Application)
sprockets.http.run(
Application,
settings={'port': 8888},
log_config={
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'readable': {
'format': '%(levelname)-13s %(name)s: %(message)s',
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'readable',
'stream': 'ext://sys.stdout',
}
},
'root': {
'level': 'DEBUG',
'handlers': ['console'],
}
},
)

View file

@ -1,13 +1,16 @@
import logging
import logging.config
import os
import warnings
version_info = (2, 0, 1)
__version__ = '.'.join(str(v) for v in version_info)
_unspecified = object()
def run(create_application, settings=None, log_config=None):
def run(create_application, settings=None, log_config=_unspecified):
"""
Run a Tornado create_application.
@ -61,8 +64,16 @@ def run(create_application, settings=None, log_config=None):
debug_mode = bool(app_settings.get('debug',
int(os.environ.get('DEBUG', 0)) != 0))
app_settings['debug'] = debug_mode
logging.config.dictConfig(_get_logging_config(debug_mode)
if log_config is None else log_config)
if log_config is _unspecified:
warnings.warn(
'calling sprockets.http.run without logging configuration is '
'deprecated and will fail in the future', DeprecationWarning)
logging.config.dictConfig(_get_logging_config(debug_mode))
logging.warning(
'calling sprockets.http.run without logging configuration is '
'deprecated and will fail in the future')
else:
logging.config.dictConfig(log_config)
port_number = int(app_settings.pop('port', os.environ.get('PORT', 8000)))
num_procs = int(app_settings.pop('number_of_procs', '0'))

View file

@ -9,6 +9,7 @@ import json
import time
import unittest
import uuid
import warnings
from tornado import concurrent, httpserver, httputil, ioloop, testing, web
@ -296,6 +297,14 @@ class RunTests(MockHelper, unittest.TestCase):
self.logging_dict_config.assert_called_once_with(
mock.sentinel.config)
def test_that_not_specifying_logging_config_is_deprecated(self):
with warnings.catch_warnings(record=True) as captured:
warnings.simplefilter('always')
sprockets.http.run(mock.Mock())
self.assertEqual(len(captured), 1)
self.assertTrue(issubclass(captured[0].category, DeprecationWarning))
class CallbackTests(MockHelper, unittest.TestCase):