Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging refactor #1048

Merged
merged 4 commits into from
Apr 20, 2020
Merged

Logging refactor #1048

merged 4 commits into from
Apr 20, 2020

Conversation

kenichi
Copy link
Member

@kenichi kenichi commented Apr 18, 2020

address #463 ( and eventually #640 ) - changes in devops make using docker drivers for logs in deployed environments a goal. to handle error notifications, a log handler can be configured, or something similar and simple to post to a slack channel.

For local dev, this PR leaves the current file logging and colorized stdout logging in place. i do recommend eventually deprecating file logging in development.

This PR also adds TIER to app.config so it can be cased on to determine logging handlers, making production use only a non-colorized stdout.

Last commit is to use syslog docker logging drivers on the production host for standardized capture, rotation, etc. With all these changes, the staging and prod images should run everything logging to stdout, which will be routed by the docker driver into syslog, configured to deliver to /var/log/recordsponge/*.log on the host. For example, SSH into the host and run: tail -f /var/log/recordsponge/staging.log, browse to the dev.recordsponge.com site, and you will see the output. standard logrotate is also configured.

@kenichi kenichi requested review from wittejm and KentShikama April 18, 2020 00:19
@kenichi kenichi self-assigned this Apr 18, 2020
Copy link
Contributor

@wittejm wittejm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I think dropping a local log file sounds good. @KentShikama, @kenichi, and myself are the only active backend developers lately so I don't think it'd be disruptive to drop it right away.

kenichi added 4 commits April 20, 2020 07:43
this function was using `logging.error()` which used the root logger,
which was being replaced in the flask app, inside
`logging.attach_logger`.
* moves `logger.setLevel` from app.py to loggers.py
* splits out `colored_stdout_handler()` and `file_handler()` from
  `attach_logger()` - for reuse in the future
when not in development, uses DetailedFormatter on STDOUT only for
running in a stand-alone, non-dev, container
* connect to syslog on host using udp
* modded /etc/rsyslog.conf:

    module(load="imudp")
    input(type="imudp" port="514" device="docker0")

* use local0, local1 syslog facilities for prod, staging respectively
* added /etc/rsyslog.d/99-recordsponge.conf:

    local1.*        /var/log/recordsponge/staging.log
    local0.*        /var/log/recordsponge/prod.log

* exclude the local0, local1 facilities from default syslog
* modded /etc/rsyslog.d/50-default.conf:

    *.*;auth,authpriv,local0,local1.none            -/var/log/syslog

* rotate normally, keeping 4 days worth
* modded /etc/logrotate.d/rsyslog:

    /var/log/recordsponge/staging.log
    /var/log/recordsponge/prod.log
@kenichi kenichi merged commit 459d5df into codeforpdx:master Apr 20, 2020
@kenichi kenichi deleted the logging_refactor branch April 20, 2020 15:24
wittejm pushed a commit that referenced this pull request Apr 22, 2020
* make request.error use current_app.logger

this function was using `logging.error()` which used the root logger,
which was being replaced in the flask app, inside
`logging.attach_logger`.

* slight refactor of logging functions

* moves `logger.setLevel` from app.py to loggers.py
* splits out `colored_stdout_handler()` and `file_handler()` from
  `attach_logger()` - for reuse in the future

* add tier to app.config, base log config on tier

when not in development, uses DetailedFormatter on STDOUT only for
running in a stand-alone, non-dev, container

* add syslog driver & opts to deployed containers

* connect to syslog on host using udp
* modded /etc/rsyslog.conf:

    module(load="imudp")
    input(type="imudp" port="514" device="docker0")

* use local0, local1 syslog facilities for prod, staging respectively
* added /etc/rsyslog.d/99-recordsponge.conf:

    local1.*        /var/log/recordsponge/staging.log
    local0.*        /var/log/recordsponge/prod.log

* exclude the local0, local1 facilities from default syslog
* modded /etc/rsyslog.d/50-default.conf:

    *.*;auth,authpriv,local0,local1.none            -/var/log/syslog

* rotate normally, keeping 4 days worth
* modded /etc/logrotate.d/rsyslog:

    /var/log/recordsponge/staging.log
    /var/log/recordsponge/prod.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants