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

Add Centralised Logging #275

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Add Centralised Logging #275

wants to merge 2 commits into from

Conversation

thebeanogamer
Copy link
Member

This is very WIP.

@codecov
Copy link

codecov bot commented May 2, 2022

Codecov Report

Merging #275 (aa64b92) into master (45ee449) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #275   +/-   ##
=======================================
  Coverage   96.88%   96.88%           
=======================================
  Files         111      112    +1     
  Lines        5131     5141   +10     
  Branches      281      281           
=======================================
+ Hits         4971     4981   +10     
  Misses        128      128           
  Partials       32       32           
Impacted Files Coverage Δ
src/backend/settings/__init__.py 90.62% <ø> (ø)
src/backend/logging.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45ee449...aa64b92. Read the comment docs.

@thebeanogamer
Copy link
Member Author

I think the way this is supposed to work is as follows:

  1. Add a logger to backend.settings.__init__.LOGGING. This is a logging destination code can send to.
  2. Define a filter in backend.logging, which shows how to transform the log
  3. Within the code you want to log from, do something like this
import logging

log = logging.getLogger("<logger name>")

log.info("Message goes here", extra={})

We probably want to send different logs to different handlers, for example sending plaintext logs to console and structured logs to syslog. We should also probably write a filter to enhance the log records by adding request and user details. The docs do imply that logging is blocking, so we might need to be careful what we do there.

@jchristgit
Copy link
Collaborator

Hi Daniel, I just got around to check this PR. It's incredible what you have implemented. Can we use https://docs.python.org/3/library/logging.handlers.html#sysloghandler instead?

record.time = datetime.now()
del record.request
record.level = record.levelname
# TODO: Get user details
Copy link
Collaborator

Choose a reason for hiding this comment

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

We won't log user details. We need to obey to GDPR

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.

None yet

2 participants