mirror of
https://github.com/sprockets/sprockets.http.git
synced 2024-11-14 11:19:26 +00:00
Deprecate calling run without a logging config.
This commit is contained in:
parent
b7b787ee31
commit
e6ef43c050
4 changed files with 51 additions and 5 deletions
|
@ -7,6 +7,8 @@ Release History
|
||||||
---------------
|
---------------
|
||||||
- Make shutdown timings configurable.
|
- Make shutdown timings configurable.
|
||||||
- Add :class:`sprockets.http.testing.SprocketsHttpTestCase`.
|
- Add :class:`sprockets.http.testing.SprocketsHttpTestCase`.
|
||||||
|
- Deprecate calling :func:`sprockets.http.run` without a specified
|
||||||
|
logging configuration.
|
||||||
|
|
||||||
`2.0.1`_ (5 Mar 2019)
|
`2.0.1`_ (5 Mar 2019)
|
||||||
----------------------
|
----------------------
|
||||||
|
|
28
examples.py
28
examples.py
|
@ -1,6 +1,7 @@
|
||||||
from tornado import web
|
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,
|
class StatusHandler(mixins.ErrorLogger, mixins.ErrorWriter,
|
||||||
|
@ -37,4 +38,27 @@ class Application(app.Application):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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'],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import os
|
import os
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
version_info = (2, 0, 1)
|
version_info = (2, 0, 1)
|
||||||
__version__ = '.'.join(str(v) for v in version_info)
|
__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.
|
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',
|
debug_mode = bool(app_settings.get('debug',
|
||||||
int(os.environ.get('DEBUG', 0)) != 0))
|
int(os.environ.get('DEBUG', 0)) != 0))
|
||||||
app_settings['debug'] = debug_mode
|
app_settings['debug'] = debug_mode
|
||||||
logging.config.dictConfig(_get_logging_config(debug_mode)
|
if log_config is _unspecified:
|
||||||
if log_config is None else log_config)
|
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)))
|
port_number = int(app_settings.pop('port', os.environ.get('PORT', 8000)))
|
||||||
num_procs = int(app_settings.pop('number_of_procs', '0'))
|
num_procs = int(app_settings.pop('number_of_procs', '0'))
|
||||||
|
|
9
tests.py
9
tests.py
|
@ -9,6 +9,7 @@ import json
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
import uuid
|
import uuid
|
||||||
|
import warnings
|
||||||
|
|
||||||
from tornado import concurrent, httpserver, httputil, ioloop, testing, web
|
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(
|
self.logging_dict_config.assert_called_once_with(
|
||||||
mock.sentinel.config)
|
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):
|
class CallbackTests(MockHelper, unittest.TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue