-
Notifications
You must be signed in to change notification settings - Fork 598
chore: cleanup libp2p logger #12058
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
chore: cleanup libp2p logger #12058
Changes from all commits
c9efe9f
0c7288e
fb2b07a
646eadf
484e361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { type ComponentLogger, type Logger } from '@libp2p/interface'; | ||
|
|
||
| import { getLogLevelFromFilters } from './log-filters.js'; | ||
| import { logFilters, logger } from './pino-logger.js'; | ||
|
|
||
| /** | ||
| * Creates a libp2p compatible logger that wraps our pino logger. | ||
| * This adapter implements the ComponentLogger interface required by libp2p. | ||
| */ | ||
| export function createLibp2pComponentLogger(namespace: string): ComponentLogger { | ||
| return { | ||
| forComponent: (component: string) => createLibp2pLogger(`${namespace}:${component}`), | ||
| }; | ||
| } | ||
|
|
||
| function createLibp2pLogger(component: string): Logger { | ||
| // Create a direct pino logger instance for libp2p that supports string interpolation | ||
| const log = logger.child({ module: component }, { level: getLogLevelFromFilters(logFilters, component) }); | ||
|
|
||
| // Default log level is trace as this is super super noisy | ||
| const logFn = (message: string, ...args: unknown[]) => { | ||
| log.trace(message, ...args); | ||
| }; | ||
|
|
||
| return Object.assign(logFn, { | ||
| enabled: log.isLevelEnabled('debug'), | ||
|
Contributor
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. I think I had already commented about whether this should be hardcoded, and you had replied, and I can't remember the answer.
Member
Author
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. Pretty much that it is extremely noisy, and we only want to be able to see it whenever we are running with LOG_LEVEL=debug and below |
||
| error(message: string, ...args: unknown[]) { | ||
| // We write error outputs as debug as they are often expected, e.g. connection errors can happen in happy paths | ||
| log.debug(message, ...args); | ||
| }, | ||
|
|
||
| debug(message: string, ...args: unknown[]) { | ||
| log.debug(message, ...args); | ||
| }, | ||
|
|
||
| info(message: string, ...args: unknown[]) { | ||
| log.info(message, ...args); | ||
| }, | ||
|
|
||
| warn(message: string, ...args: unknown[]) { | ||
| log.warn(message, ...args); | ||
| }, | ||
|
|
||
| trace(message: string, ...args: unknown[]) { | ||
| log.trace(message, ...args); | ||
| }, | ||
| }); | ||
| } | ||
This file was deleted.
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 should add
libp2p/interfaceto foundation's dev dependencies