Comparing version 9.3.2 to 9.4.0
@@ -37,1 +37,5 @@ # Bundling | ||
[esbuild-plugin-pino](https://github.com/davipon/esbuild-plugin-pino) is the esbuild plugin to generate extra pino files for bundling. | ||
## Bun Plugin | ||
[bun-plugin-pino](https://github.com/vktrl/bun-plugin-pino) is the Bun plugin to generate extra pino files for bundling. |
@@ -87,4 +87,4 @@ # Transports | ||
What if we wanted to use both transports, but send only error logs to `some-file-transport` while | ||
sending all logs to `my-transport.mjs`? We can use the `pino.transport` function's `destinations` option: | ||
What if we wanted to use both transports, but send only error logs to `my-transport.mjs` while | ||
sending all logs to `some-file-transport`? We can use the `pino.transport` function's `level` option: | ||
@@ -91,0 +91,0 @@ ```js |
'use strict' | ||
module.exports = { version: '9.3.2' } | ||
module.exports = { version: '9.4.0' } |
{ | ||
"name": "pino", | ||
"version": "9.3.2", | ||
"version": "9.4.0", | ||
"description": "super fast, all natural json logger", | ||
@@ -64,5 +64,5 @@ "main": "pino.js", | ||
"@types/flush-write-stream": "^1.0.0", | ||
"@types/node": "^20.2.3", | ||
"@types/node": "^22.0.0", | ||
"@types/tap": "^15.0.6", | ||
"@yao-pkg/pkg": "5.12.0", | ||
"@yao-pkg/pkg": "5.12.1", | ||
"airtap": "4.0.4", | ||
@@ -69,0 +69,0 @@ "benchmark": "^2.1.4", |
@@ -34,3 +34,17 @@ // Project: https://github.com/pinojs/pino.git, http://getpino.io | ||
type CustomLevelLogger<CustomLevels extends string> = { [level in CustomLevels]: LogFn } | ||
type CustomLevelLogger<CustomLevels extends string, UseOnlyCustomLevels extends boolean = boolean> = { | ||
/** | ||
* Define additional logging levels. | ||
*/ | ||
customLevels: { [level in CustomLevels]: number }; | ||
/** | ||
* Use only defined `customLevels` and omit Pino's levels. | ||
*/ | ||
useOnlyCustomLevels: UseOnlyCustomLevels; | ||
} & { | ||
// This will override default log methods | ||
[K in Exclude<pino.Level, CustomLevels>]: UseOnlyCustomLevels extends true ? never : pino.LogFn; | ||
} & { | ||
[level in CustomLevels]: pino.LogFn; | ||
}; | ||
@@ -49,3 +63,3 @@ /** | ||
export interface LoggerExtras<CustomLevels extends string = never> extends EventEmitter { | ||
export interface LoggerExtras<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean> extends EventEmitter { | ||
/** | ||
@@ -63,10 +77,2 @@ * Exposes the Pino package version. Also available on the exported pino function. | ||
/** | ||
* Define additional logging levels. | ||
*/ | ||
customLevels: { [level in CustomLevels]: number }; | ||
/** | ||
* Use only defined `customLevels` and omit Pino's levels. | ||
*/ | ||
useOnlyCustomLevels: boolean; | ||
/** | ||
* Returns the integer value for the logger instance's logging level. | ||
@@ -101,8 +107,8 @@ */ | ||
*/ | ||
on(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels>): this; | ||
addListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels>): this; | ||
once(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels>): this; | ||
prependListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels>): this; | ||
prependOnceListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels>): this; | ||
removeListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels>): this; | ||
on(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels, UseOnlyCustomLevels>): this; | ||
addListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels, UseOnlyCustomLevels>): this; | ||
once(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels, UseOnlyCustomLevels>): this; | ||
prependListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels, UseOnlyCustomLevels>): this; | ||
prependOnceListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels, UseOnlyCustomLevels>): this; | ||
removeListener(event: "level-change", listener: pino.LevelChangeEventListener<CustomLevels, UseOnlyCustomLevels>): this; | ||
@@ -232,3 +238,3 @@ /** | ||
type LevelChangeEventListener<CustomLevels extends string = never> = ( | ||
type LevelChangeEventListener<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean> = ( | ||
lvl: LevelWithSilentOrString, | ||
@@ -238,3 +244,3 @@ val: number, | ||
prevVal: number, | ||
logger: Logger<CustomLevels> | ||
logger: Logger<CustomLevels, UseOnlyCustomLevels> | ||
) => void; | ||
@@ -244,3 +250,3 @@ | ||
type Logger<CustomLevels extends string = never> = BaseLogger & LoggerExtras<CustomLevels> & CustomLevelLogger<CustomLevels>; | ||
type Logger<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean> = BaseLogger & LoggerExtras<CustomLevels> & CustomLevelLogger<CustomLevels, UseOnlyCustomLevels>; | ||
@@ -331,3 +337,3 @@ type SerializedError = pinoStdSerializers.SerializedError; | ||
interface LoggerOptions<CustomLevels extends string = never> { | ||
interface LoggerOptions<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean> { | ||
transport?: TransportSingleOptions | TransportMultiOptions | TransportPipelineOptions | ||
@@ -366,3 +372,11 @@ /** | ||
customLevels?: { [level in CustomLevels]: number }; | ||
/** | ||
* Use this option to only use defined `customLevels` and omit Pino's levels. | ||
* Logger's default `level` must be changed to a value in `customLevels` in order to use `useOnlyCustomLevels` | ||
* Warning: this option may not be supported by downstream transports. | ||
*/ | ||
useOnlyCustomLevels?: UseOnlyCustomLevels; | ||
/** | ||
* Use this option to define custom comparison of log levels. | ||
@@ -373,8 +387,2 @@ * Useful to compare custom log levels or non-standard level values. | ||
levelComparison?: "ASC" | "DESC" | ((current: number, expected: number) => boolean); | ||
/** | ||
* Use this option to only use defined `customLevels` and omit Pino's levels. | ||
* Logger's default `level` must be changed to a value in `customLevels` in order to use `useOnlyCustomLevels` | ||
* Warning: this option may not be supported by downstream transports. | ||
*/ | ||
useOnlyCustomLevels?: boolean; | ||
@@ -822,3 +830,3 @@ /** | ||
*/ | ||
declare function pino<CustomLevels extends string = never>(optionsOrStream?: LoggerOptions<CustomLevels> | DestinationStream): Logger<CustomLevels>; | ||
declare function pino<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean>(optionsOrStream?: LoggerOptions<CustomLevels, UseOnlyCustomLevels> | DestinationStream): Logger<CustomLevels, UseOnlyCustomLevels>; | ||
@@ -831,3 +839,3 @@ /** | ||
*/ | ||
declare function pino<CustomLevels extends string = never>(options: LoggerOptions<CustomLevels>, stream?: DestinationStream | undefined): Logger<CustomLevels>; | ||
declare function pino<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean>(options: LoggerOptions<CustomLevels, UseOnlyCustomLevels>, stream?: DestinationStream | undefined): Logger<CustomLevels, UseOnlyCustomLevels>; | ||
@@ -855,3 +863,3 @@ | ||
export type LogDescriptor = pino.LogDescriptor; | ||
export type Logger<CustomLevels extends string = never> = pino.Logger<CustomLevels>; | ||
export type Logger<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean> = pino.Logger<CustomLevels, UseOnlyCustomLevels>; | ||
export type SerializedError = pino.SerializedError; | ||
@@ -870,3 +878,3 @@ export type SerializerFn = pino.SerializerFn; | ||
export interface LogFn extends pino.LogFn {} | ||
export interface LoggerOptions<CustomLevels extends string = never> extends pino.LoggerOptions<CustomLevels> {} | ||
export interface LoggerOptions<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean> extends pino.LoggerOptions<CustomLevels, UseOnlyCustomLevels> {} | ||
export interface MultiStreamOptions extends pino.MultiStreamOptions {} | ||
@@ -873,0 +881,0 @@ export interface MultiStreamRes<TLevel = Level> extends pino.MultiStreamRes<TLevel> {} |
@@ -91,2 +91,5 @@ 'use strict' | ||
const { opts, stream } = normalize(instance, caller(), ...args) | ||
if (opts.level && typeof opts.level === 'string' && DEFAULT_LEVELS[opts.level.toLowerCase()] !== undefined) opts.level = opts.level.toLowerCase() | ||
const { | ||
@@ -93,0 +96,0 @@ redact, |
@@ -707,1 +707,67 @@ 'use strict' | ||
}) | ||
test('accepts capital letter for INFO level', async ({ equal }) => { | ||
const stream = sink() | ||
const logger = pino({ | ||
level: 'INFO' | ||
}, stream) | ||
logger.info('test') | ||
const { level } = await once(stream, 'data') | ||
equal(level, 30) | ||
}) | ||
test('accepts capital letter for FATAL level', async ({ equal }) => { | ||
const stream = sink() | ||
const logger = pino({ | ||
level: 'FATAL' | ||
}, stream) | ||
logger.fatal('test') | ||
const { level } = await once(stream, 'data') | ||
equal(level, 60) | ||
}) | ||
test('accepts capital letter for ERROR level', async ({ equal }) => { | ||
const stream = sink() | ||
const logger = pino({ | ||
level: 'ERROR' | ||
}, stream) | ||
logger.error('test') | ||
const { level } = await once(stream, 'data') | ||
equal(level, 50) | ||
}) | ||
test('accepts capital letter for WARN level', async ({ equal }) => { | ||
const stream = sink() | ||
const logger = pino({ | ||
level: 'WARN' | ||
}, stream) | ||
logger.warn('test') | ||
const { level } = await once(stream, 'data') | ||
equal(level, 40) | ||
}) | ||
test('accepts capital letter for DEBUG level', async ({ equal }) => { | ||
const stream = sink() | ||
const logger = pino({ | ||
level: 'DEBUG' | ||
}, stream) | ||
logger.debug('test') | ||
const { level } = await once(stream, 'data') | ||
equal(level, 20) | ||
}) | ||
test('accepts capital letter for TRACE level', async ({ equal }) => { | ||
const stream = sink() | ||
const logger = pino({ | ||
level: 'TRACE' | ||
}, stream) | ||
logger.trace('test') | ||
const { level } = await once(stream, 'data') | ||
equal(level, 10) | ||
}) |
import { IncomingMessage, ServerResponse } from "http"; | ||
import { Socket } from "net"; | ||
import { expectError, expectType } from 'tsd'; | ||
import P, { pino } from "../../"; | ||
import P, { LoggerOptions, pino } from "../../"; | ||
import Logger = P.Logger; | ||
@@ -441,2 +441,25 @@ | ||
expectError(pino({ levelComparison: () => 1 }), process.stdout); | ||
expectError(pino({ levelComparison: () => 'string' }), process.stdout); | ||
expectError(pino({ levelComparison: () => 'string' }), process.stdout); | ||
const customLevelsOnlyOpts = { | ||
useOnlyCustomLevels: true, | ||
customLevels: { | ||
customDebug: 10, | ||
info: 20, // to make sure the default names are also available for override | ||
customNetwork: 30, | ||
customError: 40, | ||
}, | ||
level: 'customDebug', | ||
} satisfies LoggerOptions; | ||
const loggerWithCustomLevelOnly = pino(customLevelsOnlyOpts); | ||
loggerWithCustomLevelOnly.customDebug('test3') | ||
loggerWithCustomLevelOnly.info('test4') | ||
loggerWithCustomLevelOnly.customError('test5') | ||
loggerWithCustomLevelOnly.customNetwork('test6') | ||
expectError(loggerWithCustomLevelOnly.fatal('test')); | ||
expectError(loggerWithCustomLevelOnly.error('test')); | ||
expectError(loggerWithCustomLevelOnly.warn('test')); | ||
expectError(loggerWithCustomLevelOnly.debug('test')); | ||
expectError(loggerWithCustomLevelOnly.trace('test')); |
@@ -1,5 +0,5 @@ | ||
import { StreamEntry, pino } from '../../pino' | ||
import { join } from 'node:path' | ||
import { tmpdir } from 'node:os' | ||
import pinoPretty from 'pino-pretty' | ||
import { LoggerOptions, StreamEntry, pino } from '../../pino' | ||
@@ -48,6 +48,6 @@ const destination = join( | ||
const customLevels = { | ||
debug : 1, | ||
customDebug : 1, | ||
info : 2, | ||
network : 3, | ||
error : 4, | ||
customNetwork : 3, | ||
customError : 4, | ||
}; | ||
@@ -58,6 +58,6 @@ | ||
const pinoOpts = { | ||
level: 'debug', | ||
useOnlyCustomLevels: true, | ||
customLevels: customLevels, | ||
}; | ||
level: 'customDebug', | ||
} satisfies LoggerOptions; | ||
@@ -70,12 +70,12 @@ const multistreamOpts = { | ||
const streams: StreamEntry<CustomLevels>[] = [ | ||
{ level : 'debug', stream : pinoPretty() }, | ||
{ level : 'customDebug', stream : pinoPretty() }, | ||
{ level : 'info', stream : pinoPretty() }, | ||
{ level : 'network', stream : pinoPretty() }, | ||
{ level : 'error', stream : pinoPretty() }, | ||
{ level : 'customNetwork', stream : pinoPretty() }, | ||
{ level : 'customError', stream : pinoPretty() }, | ||
]; | ||
const loggerCustomLevel = pino(pinoOpts, pino.multistream(streams, multistreamOpts)); | ||
loggerCustomLevel.debug('test3') | ||
loggerCustomLevel.customDebug('test3') | ||
loggerCustomLevel.info('test4') | ||
loggerCustomLevel.error('test5') | ||
loggerCustomLevel.network('test6') | ||
loggerCustomLevel.customError('test5') | ||
loggerCustomLevel.customNetwork('test6') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
737409
14757
198