-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Consolidate logging and introduce auto-prefix #7731
Consolidate logging and introduce auto-prefix #7731
Conversation
257aa46
to
2eb7a0e
Compare
return (message, ...data) => { | ||
winstonLogger[scenario]( | ||
di.sourceNamespace | ||
? `[${screamingKebabCase(di.sourceNamespace)}]: ${message}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice: di.sourceNamespace
is a new thing in injectable
, making this auto-prefixing possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the already existing prefixedLogger
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because after this you don't have to worry about prefixing at all anymore. It's all done automatically within loggerFeature
. Usage doesn't have to know about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of inconsistency, boilerplate and unnecessary complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More interestingly, I'm thinking how di.sourceNamespace
could be leveraged elsewhere. With it, we can have stuff that is guaranteed to have a Feature-specific instance.
- We can simplify injections eg. for less required
instantiationParameters
. - We can have error handling that can identify problematic Features.
- We can have profiling that can identify slow Features.
- We can have Features able to only access its own directory in file-system.
- We can solve many naming collision issues, as namespace is always guaranteed unique.
- ...best ideas win a prize at next team event ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
profile the loading time of the app so we can get closer to sub 2second loading
and send that someplace that can be seen from metabase.
I'd like to be able to see the mean load time across the userbase by release
export type LogFunction = (message: string, ...data: any[]) => void; | ||
|
||
export const logDebugInjectionToken = getInjectionToken<LogFunction>({ | ||
id: "log-debug-injection-token", | ||
}); | ||
|
||
export const logInfoInjectionToken = getInjectionToken<LogFunction>({ | ||
id: "log-info-injection-token", | ||
}); | ||
|
||
export const logWarningInjectionToken = getInjectionToken<LogFunction>({ | ||
id: "log-warning-injection-token", | ||
}); | ||
|
||
export const logErrorInjectionToken = getInjectionToken<LogFunction>({ | ||
id: "log-error-injection-token", | ||
}); | ||
|
||
export const logSillyInjectionToken = getInjectionToken<LogFunction>({ | ||
id: "log-silly-injection-token", | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also why are these categorically better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending from something that you don't use completely is considered as bad practice. (Interface segregation principle) E.g. if you depend from logger
which is object containing multiple methods, you'll likely use only one of them. This means that e.g. in the unit tests you have to override stuff that you are not interested.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
2eb7a0e
to
1dec61f
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Auto-prefix means that when in Feature with id "some-feature", usages of eg.
logErrorInjectionToken
will have[SOME-FEATURE]:
as prefix.eg.