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

Logger improvements (foundations) #1556

Merged
merged 6 commits into from
Sep 30, 2024
Merged

Conversation

joshk
Copy link
Collaborator

@joshk joshk commented Sep 27, 2024

This is based on how Phoenix and other libs use telemetry for logging requests, in fact, we also use telemetry for logging, so this is just following that best practice as well.

I have more code related to this, but I wanted to create a PR for these changes first so we can have any discussions around the approach.

The :mfa information is excluded from the log by default but can be added back in by using LOG_INCLUDE_MFA=true

@joshk joshk requested a review from oestrich September 27, 2024 00:56
Copy link
Contributor

@oestrich oestrich left a comment

Choose a reason for hiding this comment

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

I like the direction of this, I'm just not sure about one of the things being dropped

@@ -1,7 +1,7 @@
defmodule NervesHub.LoggerFormatter do
@pattern Logger.Formatter.compile("$time [$level] $metadata$message\n")
def format(level, message, timestamp, metadata) do
metadata = Keyword.drop(metadata, [:line, :file, :domain, :application])
metadata = Keyword.drop(metadata, [:line, :file, :domain, :application, :mfa, :pid])
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only thing I'm unsure of. We might use the mfa for something, I'll check tomorrow

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the feedback. From my experience, mfa is mostly noise as it always has the same output of which function and module the logging came from, which is always one of the reporters.

If SmartRent would like to keep it, I'll look into how we can make this a runtime config.

Copy link
Contributor

Choose a reason for hiding this comment

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

It has been useful in the past to establish consistency for log identification and grouping, so I/SmartRent would like to retain the ability to have :mfa in the logs if its not too much trouble.

:pid can happily go 🙇

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the feedback @rraub , I'll make this configurable as I believe its noise for the majority of people. It will mean that you will need to add an env var to enable it, is that alright with you? (I'll document the env var in the PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rraub I've updated the PR, as well as documenting in the PR description how to enable :mfa information. (I need to work on some more complete docs on all the env vars and how they are used)

Copy link
Contributor

@oestrich oestrich left a comment

Choose a reason for hiding this comment

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

:shipit:

@joshk joshk merged commit 6419141 into main Sep 30, 2024
2 checks passed
@joshk joshk deleted the logger-improvement-foundations branch September 30, 2024 21:16
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