4 Commits

Author SHA1 Message Date
a51fbc33ea Fix tox environment list 2018-01-30 20:14:26 +01:00
41bcdc4b0b Merge pull request #2 from gergelypolonkai/autoconfigure
Configure automatically with current_app
2018-01-30 14:40:52 +01:00
b9c3128315 Configure automatically with current_app 2018-01-30 14:36:20 +01:00
fbebc6ca26 [Dev] Remove Python 3.3 from the TOX list 2018-01-30 14:36:20 +01:00
5 changed files with 23 additions and 10 deletions

View File

@@ -1,12 +1,11 @@
language: python
python:
- "3.5"
- "3.6"
sudo: false
env:
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34
- TOXENV=py35
- TOXENV=py36
install:
- pip install -U pip
- pip install -U Flask tox coverage codecov

View File

@@ -32,7 +32,7 @@ no value is present in the message record.
import logging
from flask import has_request_context, request
from flask import has_request_context, request, current_app, has_app_context
__version_info__ = ('0', '0', '1')
__version__ = '.'.join(__version_info__)
@@ -129,6 +129,9 @@ class FlaskExtraLogger(logging.getLoggerClass()):
super(FlaskExtraLogger, self).__init__(*args, **kwargs)
def _log(self, *args, **kwargs):
if has_app_context() and self.app is None:
self.init_app(current_app)
if 'extra' not in kwargs:
kwargs['extra'] = {}
@@ -172,6 +175,8 @@ class FlaskExtraLogger(logging.getLoggerClass()):
reserved for internal use
"""
self.app = app
app.config.setdefault('FLASK_LOGGING_EXTRAS_KEYWORDS', {})
app.config.setdefault('FLASK_LOGGING_EXTRAS_BLUEPRINT',
(None, '<app>', '<not a request>'))

View File

@@ -8,7 +8,7 @@ Flask-Logging-Extras provides extra logging functionality for Flask apps.
from setuptools import setup
setup(name='Flask-Logging-Extras',
version='0.1.0',
version='0.1.1',
url='https://github.com/gergelypolonkai/flask-logging-extras',
license='MIT',
author='Gergely Polonkai',

View File

@@ -191,10 +191,10 @@ class LoggerBlueprintTestCase(TestCase):
self.stream = ListStream()
formatter = logging.Formatter(fmt)
handler = TestingStreamHandler(stream=self.stream)
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
self.handler = TestingStreamHandler(stream=self.stream)
self.handler.setLevel(logging.DEBUG)
self.handler.setFormatter(formatter)
app.logger.addHandler(self.handler)
app.logger.setLevel(logging.DEBUG)
bp = Blueprint('test_blueprint', 'test_bpg13')
@@ -218,6 +218,15 @@ class LoggerBlueprintTestCase(TestCase):
def tearDown(self):
logging.setLoggerClass(self.original_logger_class)
def test_autoconfig(self):
logger = logging.getLogger('test')
logger.addHandler(self.handler)
with self.app.app_context():
logger.warning('Hello')
self.assertEqual('<norequest> Hello\n', self.stream.lines[-1])
def test_request_log(self):
self.client.get('/app')
self.assertEqual('<app> Message\n', self.stream.lines[-1])

View File

@@ -1,5 +1,5 @@
[tox]
envlist = py27, py33, py34, py35, py36
envlist = py27, py34, py36
[testenv]
commands =