Add support for JSON logging

This commit is contained in:
Curtis Castrapel 2019-05-17 08:48:26 -07:00
parent 37e5857406
commit 4fac726cf4
6 changed files with 21 additions and 9 deletions

View File

@ -13,11 +13,13 @@ import os
import imp import imp
import errno import errno
import pkg_resources import pkg_resources
import socket
from logging import Formatter, StreamHandler from logging import Formatter, StreamHandler
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
from flask import Flask from flask import Flask
import logmatic
from lemur.certificates.hooks import activate_debug_dump from lemur.certificates.hooks import activate_debug_dump
from lemur.common.health import mod as health from lemur.common.health import mod as health
@ -172,6 +174,11 @@ def configure_logging(app):
) )
) )
if app.config.get("LOG_JSON", False):
handler.setFormatter(
logmatic.JsonFormatter(extra={"hostname": socket.gethostname()})
)
handler.setLevel(app.config.get("LOG_LEVEL", "DEBUG")) handler.setLevel(app.config.get("LOG_LEVEL", "DEBUG"))
app.logger.setLevel(app.config.get("LOG_LEVEL", "DEBUG")) app.logger.setLevel(app.config.get("LOG_LEVEL", "DEBUG"))
app.logger.addHandler(handler) app.logger.addHandler(handler)

View File

@ -33,4 +33,4 @@ twine==1.13.0
urllib3==1.25.2 # via requests urllib3==1.25.2 # via requests
virtualenv==16.6.0 # via pre-commit virtualenv==16.6.0 # via pre-commit
webencodings==0.5.1 # via bleach webencodings==0.5.1 # via bleach
zipp==0.5.0 # via importlib-metadata zipp==0.5.1 # via importlib-metadata

View File

@ -17,8 +17,8 @@ babel==2.6.0 # via sphinx
bcrypt==3.1.6 bcrypt==3.1.6
billiard==3.6.0.0 billiard==3.6.0.0
blinker==1.4 blinker==1.4
boto3==1.9.149 boto3==1.9.150
botocore==1.12.149 botocore==1.12.150
celery[redis]==4.3.0 celery[redis]==4.3.0
certifi==2019.3.9 certifi==2019.3.9
certsrv==2.1.1 certsrv==2.1.1
@ -54,6 +54,7 @@ josepy==1.1.0
jsonlines==1.2.0 jsonlines==1.2.0
kombu==4.5.0 kombu==4.5.0
lockfile==0.12.2 lockfile==0.12.2
logmatic-python==0.1.7
mako==1.0.10 mako==1.0.10
markupsafe==1.1.1 markupsafe==1.1.1
marshmallow-sqlalchemy==0.16.3 marshmallow-sqlalchemy==0.16.3
@ -77,6 +78,7 @@ pyparsing==2.4.0 # via packaging
pyrfc3339==1.1 pyrfc3339==1.1
python-dateutil==2.8.0 python-dateutil==2.8.0
python-editor==1.0.4 python-editor==1.0.4
python-json-logger==0.1.11
pytz==2019.1 pytz==2019.1
pyyaml==5.1 pyyaml==5.1
raven[flask]==6.10.0 raven[flask]==6.10.0

View File

@ -12,12 +12,12 @@ aws-sam-translator==1.11.0 # via cfn-lint
aws-xray-sdk==2.4.2 # via moto aws-xray-sdk==2.4.2 # via moto
bandit==1.6.0 bandit==1.6.0
black==19.3b0 black==19.3b0
boto3==1.9.149 # via aws-sam-translator, moto boto3==1.9.150 # via aws-sam-translator, moto
boto==2.49.0 # via moto boto==2.49.0 # via moto
botocore==1.12.149 # via aws-xray-sdk, boto3, moto, s3transfer botocore==1.12.150 # via aws-xray-sdk, boto3, moto, s3transfer
certifi==2019.3.9 # via requests certifi==2019.3.9 # via requests
cffi==1.12.3 # via cryptography cffi==1.12.3 # via cryptography
cfn-lint==0.20.2 # via moto cfn-lint==0.20.3 # via moto
chardet==3.0.4 # via requests chardet==3.0.4 # via requests
click==7.0 # via black, flask click==7.0 # via black, flask
coverage==4.5.3 coverage==4.5.3
@ -61,7 +61,7 @@ python-jose==3.0.1 # via moto
pytz==2019.1 # via moto pytz==2019.1 # via moto
pyyaml==5.1 pyyaml==5.1
requests-mock==1.6.0 requests-mock==1.6.0
requests==2.22.0 # via cfn-lint, docker, moto, requests-mock, responses requests==2.21.0 # via cfn-lint, docker, moto, requests-mock, responses
responses==0.10.6 # via moto responses==0.10.6 # via moto
rsa==4.0 # via python-jose rsa==4.0 # via python-jose
s3transfer==0.2.0 # via boto3 s3transfer==0.2.0 # via boto3

View File

@ -29,6 +29,7 @@ inflection
jinja2 jinja2
kombu kombu
lockfile lockfile
logmatic-python
marshmallow-sqlalchemy marshmallow-sqlalchemy
marshmallow marshmallow
ndg-httpsclient ndg-httpsclient

View File

@ -15,8 +15,8 @@ asyncpool==1.0
bcrypt==3.1.6 # via flask-bcrypt, paramiko bcrypt==3.1.6 # via flask-bcrypt, paramiko
billiard==3.6.0.0 # via celery billiard==3.6.0.0 # via celery
blinker==1.4 # via flask-mail, flask-principal, raven blinker==1.4 # via flask-mail, flask-principal, raven
boto3==1.9.149 boto3==1.9.150
botocore==1.12.149 botocore==1.12.150
celery[redis]==4.3.0 celery[redis]==4.3.0
certifi==2019.3.9 certifi==2019.3.9
certsrv==2.1.1 certsrv==2.1.1
@ -51,6 +51,7 @@ josepy==1.1.0 # via acme
jsonlines==1.2.0 # via cloudflare jsonlines==1.2.0 # via cloudflare
kombu==4.5.0 kombu==4.5.0
lockfile==0.12.2 lockfile==0.12.2
logmatic-python==0.1.7
mako==1.0.10 # via alembic mako==1.0.10 # via alembic
markupsafe==1.1.1 # via jinja2, mako markupsafe==1.1.1 # via jinja2, mako
marshmallow-sqlalchemy==0.16.3 marshmallow-sqlalchemy==0.16.3
@ -71,6 +72,7 @@ pyopenssl==19.0.0
pyrfc3339==1.1 # via acme pyrfc3339==1.1 # via acme
python-dateutil==2.8.0 # via alembic, arrow, botocore python-dateutil==2.8.0 # via alembic, arrow, botocore
python-editor==1.0.4 # via alembic python-editor==1.0.4 # via alembic
python-json-logger==0.1.11 # via logmatic-python
python-ldap==3.2.0 python-ldap==3.2.0
pytz==2019.1 # via acme, celery, flask-restful, pyrfc3339 pytz==2019.1 # via acme, celery, flask-restful, pyrfc3339
pyyaml==5.1 pyyaml==5.1