-
Notifications
You must be signed in to change notification settings - Fork 1
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 logging #61
Merged
Merged
Refactor logging #61
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5977bf5
feat: add NodekitLogger to remove direct dependency on pino
main-kun 02389fc
feat: add logWarn method to context
main-kun 4c4add8
refactor: clean up logError to match logWarn
main-kun 735efb9
fix: bring back old behavior for building logObject
main-kun 1c90bfd
feat: add more logging methods
main-kun 1ea79d2
feat: add appLogger option to Nodekit config
main-kun 7ef5a37
style: correctly capitalize NodeKit
main-kun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,79 @@ | ||
import pino from 'pino'; | ||
import {Dict} from '../types'; | ||
|
||
export interface NodeKitLogger { | ||
info(message: string): void; | ||
info(extra: Dict | undefined, message: string): void; | ||
|
||
error(message: string): void; | ||
error(extra: Dict | undefined, message: string): void; | ||
|
||
warn(message: string): void; | ||
warn(extra: Dict | undefined, message: string): void; | ||
|
||
trace(message: string): void; | ||
trace(extra: Dict | undefined, message: string): void; | ||
|
||
debug(message: string): void; | ||
debug(extra: Dict | undefined, message: string): void; | ||
} | ||
|
||
export class PinoLogger implements NodeKitLogger { | ||
private logger: pino.Logger; | ||
|
||
constructor(logger: pino.Logger) { | ||
this.logger = logger; | ||
} | ||
info(message: string): void; | ||
info(extra: Dict | undefined, message: string): void; | ||
info(msgOrExtra: string | Dict | undefined, message?: string): void { | ||
if (typeof msgOrExtra === 'string') { | ||
this.logger.info(message); | ||
} else { | ||
this.logger.info(msgOrExtra, message); | ||
} | ||
} | ||
|
||
warn(message: string): void; | ||
warn(extra: Dict | undefined, message: string): void; | ||
warn(msgOrExtra: string | Dict | undefined, message?: string): void { | ||
if (typeof msgOrExtra === 'string') { | ||
this.logger.info(message); | ||
} else { | ||
this.logger.info(msgOrExtra, message); | ||
} | ||
} | ||
|
||
error(message: string): void; | ||
error(extra: Dict | undefined, message: string): void; | ||
error(msgOrExtra: string | Dict | undefined, message?: string): void { | ||
if (typeof msgOrExtra === 'string') { | ||
this.logger.error(message); | ||
} else { | ||
this.logger.error(msgOrExtra, message); | ||
} | ||
} | ||
|
||
trace(message: string): void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #60 - will be used here. We're gonna have to merge this one first and rebase the opentracing one on top of this. |
||
trace(extra: Dict | undefined, message: string): void; | ||
trace(msgOrExtra: string | Dict | undefined, message?: string): void { | ||
if (typeof msgOrExtra === 'string') { | ||
this.logger.trace(message); | ||
} else { | ||
this.logger.trace(msgOrExtra, message); | ||
} | ||
} | ||
|
||
debug(message: string): void; | ||
debug(extra: Dict | undefined, message: string): void; | ||
debug(msgOrExtra: string | Dict | undefined, message?: string): void { | ||
if (typeof msgOrExtra === 'string') { | ||
this.logger.debug(message); | ||
} else { | ||
this.logger.debug(msgOrExtra, message); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* workaround to provide IntelliSense hints https://stackoverflow.com/a/61048124 | ||
|
@@ -34,9 +109,12 @@ export function initLogger({appName, devMode, destination, level = 'debug'}: Ini | |
transport: transportConfig, | ||
}; | ||
|
||
let pinoInstance: pino.Logger; | ||
if (destination && !devMode) { | ||
return pino(options, destination); | ||
pinoInstance = pino(options, destination); | ||
} else { | ||
return pino(options); | ||
pinoInstance = pino(options); | ||
} | ||
|
||
return new PinoLogger(pinoInstance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shouldn't message be first argument (for consistency with context class loggers)? Or it would be better to be consistent with pino logger class methods?
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.
The intention was to be consistent with
pino
first. I think it makes sense to do this rather than reorder the arguments of every call to the logger.