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

refactor all log messages to use same format, overhaul logExtension #190

Merged
merged 5 commits into from
Apr 6, 2022

Conversation

lukasIO
Copy link
Contributor

@lukasIO lukasIO commented Apr 5, 2022

motivation:
a more structured approach to logging in order to facilitate sending logs to third party services.

structuring the logs with a message string and an optional context object turned out to be the most flexible approach while not forcing us to rewrite all messages.
some logging implementations that utilize a similar structure:

I opted to go for the ordering of arguments (msg: string, context?: object) instead of (context?: object, msg: string), but not sure anymore if it's the right bet, as the implementations mentioned above seem to switch things around.

src/room/participant/LocalParticipant.ts Outdated Show resolved Hide resolved
src/room/participant/LocalParticipant.ts Outdated Show resolved Hide resolved
update.trackSid,
);
log.warn('received subscribed quality update for unknown track', {
method: 'handleSubscribedQualityUpdate',
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you are using method here as an indicator. I am guessing this log line is unique and does not need context. But, it would be nice to have file/line/function name in some way. Not sure that is even possible with TS.

Copy link
Contributor Author

@lukasIO lukasIO Apr 5, 2022

Choose a reason for hiding this comment

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

when piping out logs we will unfortunately lose native line number indicators.
The workaround to get a stacktrace would be to throw an Error manually and look at its trace.
For file and method names other loggers have the concept of childloggers, which would allow to have an own logger for each file and have that info (e.g. filename) be part of the context object automatically.

For now I didn't swap out the underlying logging library we are using, but we could either just use a different one or provide some functionality like that ourselves

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you @lukasIO . Guess it can be an improvement (or not :-) ) down the line.

@lukasIO lukasIO merged commit de9dfb2 into main Apr 6, 2022
@lukasIO lukasIO deleted the lukas/structured-logging branch April 6, 2022 06:53
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

3 participants