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 logging framework #231

Merged
merged 4 commits into from
Sep 21, 2024
Merged

Conversation

jamescurtin
Copy link
Collaborator

Closes #204

Easiest to review by commit.

Note that there will be two new files that are created in the root of the repo containing all log messages:

  • logs/django.log
  • logs/root.log

The first will contain log messages that are created by django itself, and the second will contain anything emitted by a logger.<log_level>('some message') line. Log rotation is enabled by default (to avoid eating up all disk space on the host with an ever-growing log file).

The format looks like:
image
Which gives you information about the log level used, when the log was emitted, the module and function (along with the line number of the log line) that emitted the message, followed by the message itself.

Note the new additions to .env.example, which will also need to be carried over to the deployment's .env file. (Note the enum of possible levels: only logs at the level set in the config file (or higher) will make it into the log file--everything with a lower level is dropped. This is nice for things like logger.debug("some message"), because you can leave them in the code and they wouldn't be printed on the production service where the log level might be INFO, for example, but would be printed when you're developing in debug mode. (As compared to a print that's emitted all the time, or needs to constantly be commented and un-commented out)

I converted over all existing prints to logs using whatever log level.

@@ -12,7 +12,6 @@ jobs:
- uses: actions/checkout@v4
- run: ./.github/scripts/prepare-ci.sh
- run: docker compose build
- run: docker compose up -d
- run: sleep 60 # Wait for the container to be up
- run: docker compose up --detach --wait --wait-timeout 60
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The --wait flag means that this will move onto the next command as soon as all of the containers are up, rather than needing to wait a fixed 60 seconds (even if the containers start up sooner). The timeout prevents this from hanging forever in case something is wrong.

@iragm
Copy link
Owner

iragm commented Sep 21, 2024

Awesome work! logger.exception is handy, I didn't know about that one. It may take some getting used to use %s instead of f-strings but makes sense.

@iragm iragm merged commit 172757a into iragm:master Sep 21, 2024
3 checks passed
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.

Logging Framework
2 participants