[READ-ONLY] Mirror of https://github.com/FoxxMD/logging. A typed, opinionated, batteries-included, Pino-based logging solution for backend TS/JS projects foxxmd.github.io/logging
child-logger logging logging-library nodejs pinojs typescript-library
0

Configure Feed

Select the types of activity you want to include in your feed.

Disable custom log levels for now

FoxxMD (Mar 8, 2024, 2:40 PM EST) 3cc62b03 d1354e2c

+53 -19
+19 -4
src/factory.ts
··· 1 - import {prettyConsole, prettyFile, PRETTY_COLORS, PRETTY_COLORS_STR, PRETTY_LEVELS, PRETTY_LEVELS_STR, PRETTY_ISO8601, prettyOptsFactory} from "./pretty.js"; 2 - import {buildDestinationStream, buildDestinationRollingFile, buildDestinationStdout, buildDestinationStderr, buildDestinationFile} from "./destinations.js"; 1 + import { 2 + prettyConsole, 3 + prettyFile, 4 + PRETTY_COLORS, 5 + PRETTY_COLORS_STR, 6 + //PRETTY_LEVELS, 7 + //PRETTY_LEVELS_STR, 8 + PRETTY_ISO8601, 9 + prettyOptsFactory 10 + } from "./pretty.js"; 11 + import { 12 + buildDestinationStream, 13 + buildDestinationRollingFile, 14 + buildDestinationStdout, 15 + buildDestinationStderr, 16 + buildDestinationFile 17 + } from "./destinations.js"; 3 18 import {buildLogger} from './loggers.js'; 4 19 import {FileDestination, StreamDestination} from './types.js' 5 20 ··· 8 23 prettyFile, 9 24 PRETTY_COLORS, 10 25 PRETTY_COLORS_STR, 11 - PRETTY_LEVELS, 12 - PRETTY_LEVELS_STR, 26 + //PRETTY_LEVELS, 27 + //PRETTY_LEVELS_STR, 13 28 PRETTY_ISO8601, 14 29 prettyOptsFactory, 15 30 buildDestinationStream,
+13 -6
src/loggers.ts
··· 1 1 import {parseLogOptions} from "./funcs.js"; 2 - import {Logger, LoggerAppExtras, LogLevel, LogLevelStreamEntry, LogOptions} from "./types.js"; 2 + import { 3 + CUSTOM_LEVELS, 4 + Logger, 5 + LoggerAppExtras, 6 + LogLevel, 7 + LogLevelStreamEntry, 8 + LogOptions 9 + } from "./types.js"; 3 10 import {buildDestinationFile, buildDestinationRollingFile, buildDestinationStdout} from "./destinations.js"; 4 11 import {pino} from "pino"; 5 12 ··· 11 18 * @see Logger 12 19 * */ 13 20 export const buildLogger = (defaultLevel: LogLevel, streams: LogLevelStreamEntry[]): Logger => { 14 - const plogger = pino({ 21 + // TODO maybe implement custom levels 22 + //const { levels = {} } = extras; 23 + 24 + const plogger = pino<"verbose" | "log">({ 15 25 // @ts-ignore 16 26 mixin: (obj, num, loggerThis) => { 17 27 return { ··· 28 38 return finalObj; 29 39 }, 30 40 level: defaultLevel, 31 - customLevels: { 32 - verbose: 25, 33 - log: 21 34 - }, 41 + customLevels: CUSTOM_LEVELS, 35 42 useOnlyCustomLevels: false, 36 43 }, pino.multistream(streams)) as Logger; 37 44 plogger.labels = [];
+10 -8
src/pretty.ts
··· 1 1 import {PrettyOptions} from "pino-pretty"; 2 2 import {CWD} from "./util.js"; 3 + import {CUSTOM_LEVELS} from "./types.js"; 3 4 4 5 /** 5 6 * Additional levels included in @foxxmd/logging as an object 6 7 * 7 8 * These are always applied when using `prettyOptsFactory` but can be overridden 8 9 * */ 9 - export const PRETTY_LEVELS: Extract<PrettyOptions['customLevels'], object> = { 10 - verbose: 25, 11 - log: 21, 12 - }; 10 + const PRETTY_LEVELS: Extract<PrettyOptions['customLevels'], object> = CUSTOM_LEVELS; 13 11 /** 14 12 * Additional levels included in @foxxmd/logging as a string 15 13 * 16 14 * These are always applied when using `prettyOptsFactory` but can be overridden 17 15 * */ 18 - export const PRETTY_LEVELS_STR: Extract<PrettyOptions['customLevels'], string> = 'verbose:25,log:21'; 16 + const PRETTY_LEVELS_STR: Extract<PrettyOptions['customLevels'], string> = 'verbose:25,log:21'; 19 17 20 18 /** 21 19 * Additional level colors included in @foxxmd/logging as an object ··· 41 39 /** 42 40 * Builds the opinionated `@foxxmd/logging` defaults for pino-pretty `PrettyOptions` and merges them with an optional user-provided `PrettyOptions` object 43 41 * */ 44 - export const prettyOptsFactory = (opts: PrettyOptions = {}): PrettyOptions => { 45 - const {customLevels = {}, customColors = {}, ...rest} = opts; 42 + export const prettyOptsFactory = (opts: Omit<PrettyOptions, 'customLevels'> = {}): PrettyOptions => { 43 + const { 44 + //customLevels = {}, 45 + customColors = {}, 46 + ...rest 47 + } = opts; 46 48 47 49 return { 48 50 messageFormat: (log, messageKey, levelLabel, {colors}) => { ··· 60 62 hideObject: false, 61 63 ignore: 'pid,hostname,labels,err', 62 64 translateTime: 'SYS:standard', 63 - customLevels: buildLevels(customLevels), 65 + customLevels: buildLevels({}), 64 66 customColors: buildColors(customColors), 65 67 colorizeObjects: true, 66 68 // @ts-ignore
+11 -1
src/types.ts
··· 1 - import {DestinationStream, Level, Logger as PinoLogger, StreamEntry} from 'pino'; 1 + import {DestinationStream, Level, Logger as PinoLogger, LoggerOptions, StreamEntry} from 'pino'; 2 2 import {ErrorWithCause} from "pony-cause"; 3 3 import {PrettyOptions} from "pino-pretty"; 4 4 import {MarkRequired} from "ts-essentials"; ··· 171 171 * */ 172 172 destinations?: LogLevelStreamEntry[] 173 173 } 174 + 175 + /** 176 + * Additional levels included in @foxxmd/logging as an object 177 + * 178 + * These are always applied when using `prettyOptsFactory` but can be overridden 179 + * */ 180 + export const CUSTOM_LEVELS: LoggerOptions<"verbose" | "log">['customLevels'] = { 181 + verbose: 25, 182 + log: 21 183 + }