-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Remove debug and winston in favor of pino
- Loading branch information
1 parent
752bc59
commit e4b2c5e
Showing
25 changed files
with
516 additions
and
595 deletions.
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
This file was deleted.
Oops, something went wrong.
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
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
2 changes: 1 addition & 1 deletion
2
yarn-project/foundation/src/crypto/random/randomness_singleton.ts
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
2 changes: 1 addition & 1 deletion
2
yarn-project/foundation/src/json-rpc/client/safe_json_rpc_client.ts
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,5 +1,5 @@ | ||
export * from './console.js'; | ||
export * from './debug.js'; | ||
export * from './logger.js'; | ||
export * from './pino-logger.js'; | ||
export * from './log_history.js'; | ||
export * from './log_fn.js'; |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { parseEnv } from './log-filters.js'; | ||
|
||
describe('parseEnv', () => { | ||
const defaultLevel = 'info'; | ||
|
||
it('returns default level and empty filters when env is empty', () => { | ||
const env = ''; | ||
const [level, filters] = parseEnv(env, defaultLevel); | ||
expect(level).toBe(defaultLevel); | ||
expect(filters).toEqual([]); | ||
}); | ||
|
||
it('parses level and filters from env string', () => { | ||
const env = 'debug;warn:module1,module2;error:module3'; | ||
const [level, filters] = parseEnv(env, defaultLevel); | ||
expect(level).toBe('debug'); | ||
expect(filters).toEqual([ | ||
['module3', 'error'], | ||
['module2', 'warn'], | ||
['module1', 'warn'], | ||
]); | ||
}); | ||
|
||
it('handles spaces in env string', () => { | ||
const env = 'debug; warn: module1, module2; error: module3'; | ||
const [level, filters] = parseEnv(env, defaultLevel); | ||
expect(level).toBe('debug'); | ||
expect(filters).toEqual([ | ||
['module3', 'error'], | ||
['module2', 'warn'], | ||
['module1', 'warn'], | ||
]); | ||
}); | ||
|
||
it('throws an error for invalid default log level', () => { | ||
const env = 'invalid;module1:warn'; | ||
expect(() => parseEnv(env, defaultLevel)).toThrow('Invalid log level: invalid'); | ||
}); | ||
|
||
it('throws an error for invalid log level in filter', () => { | ||
const env = 'invalid;warn:module'; | ||
expect(() => parseEnv(env, defaultLevel)).toThrow('Invalid log level: invalid'); | ||
}); | ||
|
||
it('throws an error for invalid log filter statement', () => { | ||
const defaultLevel = 'info'; | ||
const env = 'debug;warn:module1;error:'; | ||
expect(() => parseEnv(env, defaultLevel)).toThrow('Invalid log filter statement: error'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { type LogLevel, LogLevels } from './log-levels.js'; | ||
|
||
export type LogFilters = [string, LogLevel][]; | ||
|
||
export function getLogLevelFromFilters(filters: LogFilters, module: string): LogLevel | undefined { | ||
for (const [filterModule, level] of filters) { | ||
if (module.startsWith(filterModule)) { | ||
return level as LogLevel; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
export function assertLogLevel(level: string): asserts level is LogLevel { | ||
if (!LogLevels.includes(level as LogLevel)) { | ||
throw new Error(`Invalid log level: ${level}`); | ||
} | ||
} | ||
|
||
export function parseEnv(env: string | undefined, defaultLevel: LogLevel): [LogLevel, LogFilters] { | ||
if (!env) { | ||
return [defaultLevel, []]; | ||
} | ||
const [level] = env.split(';', 1); | ||
assertLogLevel(level); | ||
return [level, parseFilters(env.slice(level.length + 1))]; | ||
} | ||
|
||
export function parseFilters(definition: string | undefined): LogFilters { | ||
if (!definition) { | ||
return []; | ||
} | ||
|
||
const statements = definition.split(';'); | ||
const filters: LogFilters = []; | ||
for (const statement of statements) { | ||
const [level] = statement.split(':', 1); | ||
const modules = statement.slice(level.length + 1); | ||
if (!modules || !level) { | ||
throw new Error(`Invalid log filter statement: ${statement}`); | ||
} | ||
const sanitizedLevel = level.trim().toLowerCase(); | ||
assertLogLevel(sanitizedLevel); | ||
for (const module of modules.split(',')) { | ||
filters.push([module.trim().toLowerCase(), sanitizedLevel as LogLevel | 'silent']); | ||
} | ||
} | ||
return filters.reverse(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const LogLevels = ['silent', 'fatal', 'error', 'warn', 'info', 'verbose', 'debug', 'trace'] as const; | ||
|
||
export type LogLevel = (typeof LogLevels)[number]; |
Oops, something went wrong.