-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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(core): Move Logger to core
(no-changelog)
#12310
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Thanks for taking this on! Code looks good, will give it a spin soon!
PS: I think we can omit (no-changelog)
for refactor
PRs
if (!this.isScopingEnabled) return info; | ||
|
||
const { scopes } = info.metadata; | ||
const { scopes } = (info as unknown as { metadata: LogMetadata }).metadata; |
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 is this better than the original?
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.
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.
So confused, this should've been erroring out in cli
then? Also the TransformableInfo
type is left open [key: string | symbol]: any;
so worst case we shouldn't need the unknown
intermediary or? info.metadata as LogMetadata
packages/core/src/utils.ts
Outdated
@@ -0,0 +1,3 @@ | |||
export function isObjectLiteral(item: unknown): item is { [key: string]: unknown } { |
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.
Nit - better naming
export function isObjectLiteral(item: unknown): item is { [key: string]: unknown } { | |
export function isObjectLiteral(candidate: unknown): candidate is { [key: string]: unknown } { |
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.
we have an exact copy of this in cli
. if we rename this, we should rename it in the other copy as well, so that if/when we deduplicate this code, it's not confusing for the person doing the refactoring.
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.
Since we're here let's keep only one copy in core
and import it from elsewhere?
export type LogMetadata = { | ||
[key: string]: unknown; | ||
scopes?: LogScope[]; | ||
file?: string; | ||
function?: string; | ||
}; | ||
export type Logger = Record< | ||
Exclude<LogLevel, 'silent'>, | ||
(message: string, metadata?: LogMetadata) => void | ||
>; | ||
export type LogLocationMetadata = Pick<LogMetadata, 'file' | 'function'>; |
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.
- Instead of picking from
LogMetadata
I wonder if it'd be more readable to defineLogLocationMetadata
as those two properties and intersect this type to createLogMetadata
? - I'm not clear just from this what
Logger
is here as opposed to theLogger
service. The proxy? Maybe we can docline this?
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.
I just copied this code over. I think we can refactor this bit in the next step when we get rid of more of the LoggerProxy
code.
if (!this.isScopingEnabled) return info; | ||
|
||
const { scopes } = info.metadata; | ||
const { scopes } = (info as unknown as { metadata: LogMetadata }).metadata; |
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.
So confused, this should've been erroring out in cli
then? Also the TransformableInfo
type is left open [key: string | symbol]: any;
so worst case we shouldn't need the unknown
intermediary or? info.metadata as LogMetadata
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 remove the .service.
infix?
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.
I prefer the file name and the DI class names to align. I can add the .service
back, but then I prefer to rename the class to LoggerService
. Would that be acceptable?
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.
Turning all the logger
references to loggerService
makes the code everywhere more verbose for little gain. Do we need to be so consistent? I always thought of the -Service
suffix as an easy way to name classes that otherwise would be hard to name like WorklowService
but that doesn't really apply for the logger.
If the alternative is making all code more verbose, I'd rather omit the .service.
infix here. But I also notice that this is also inconsistent in that we're having some DI services infixed and some not.
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.
we don't need to rename all variables. I just meant the class. So the only change would be change the class name in this file to LoggerService
, and renaming the file back to logger.service.ts
.
however I personally the Service
suffix in this particular case not very useful.
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.
however I personally the Service suffix in this particular case not very useful.
Agree! In any case if this renaming won't cause lots of changes everywhere, I'd be happy with what you decide.
packages/core/src/utils.ts
Outdated
@@ -0,0 +1,3 @@ | |||
export function isObjectLiteral(item: unknown): item is { [key: string]: unknown } { |
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.
Since we're here let's keep only one copy in core
and import it from elsewhere?
Summary
This PR moved the
Logger
ton8n-core
, so that we can stop usingconsole.*
andLoggerproxy
in more places.Review / Merge checklist
release/backport
(if the PR is an urgent fix that needs to be backported)