[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.

Unify log levels constants with type

FoxxMD (Feb 29, 2024, 11:45 AM EST) 38f7231e 13236ee0

+8 -9
-1
src/funcs.ts
··· 15 15 import pinoRoll from 'pino-roll'; 16 16 import prettyDef, {PrettyOptions} from 'pino-pretty'; 17 17 import {createColors} from 'colorette'; 18 - import * as Colorette from "colorette"; 19 18 import {fileOrDirectoryIsWriteable} from "./util.js"; 20 19 21 20 const projectDir = process.cwd();
+6 -6
src/types.ts
··· 2 2 import {ErrorWithCause} from "pony-cause"; 3 3 4 4 export type AdditionalLevels = "verbose" | "log"; 5 - export type AllLevels = Level | AdditionalLevels; 6 - export type LogLevel = AllLevels; 7 - export const logLevels: LogLevel[] = ['fatal', 'error', 'warn', 'info', 'verbose', 'debug']; 5 + export type AllLevels = typeof LOGLEVELS[number]; 6 + export type LogLevel = AllLevels 7 + export const LOGLEVELS= ['fatal', 'error', 'warn', 'info', 'log', 'verbose', 'debug'] as (Level | AdditionalLevels)[]; 8 8 9 9 export interface LogOptions { 10 10 /** ··· 32 32 return false; 33 33 } 34 34 if (key !== 'file') { 35 - return val === undefined || logLevels.includes(val.toLocaleLowerCase()); 35 + return val === undefined || LOGLEVELS.includes(val.toLocaleLowerCase()); 36 36 } 37 - return val === undefined || val === false || logLevels.includes(val.toLocaleLowerCase()); 37 + return val === undefined || val === false || LOGLEVELS.includes(val.toLocaleLowerCase()); 38 38 }); 39 39 } 40 40 41 - export type LabelledLogger = Logger<AllLevels> & { 41 + export type LabelledLogger = Logger<LogLevel> & { 42 42 labels: any[] 43 43 addLabel: (value: any) => void 44 44 }
+2 -2
tests/index.test.ts
··· 5 5 import chai, {expect} from "chai"; 6 6 import {pEvent} from 'p-event'; 7 7 import {sleep} from "../src/util.js"; 8 - import {LogData, logLevels} from "../src/types.js"; 8 + import {LogData, LOGLEVELS} from "../src/types.js"; 9 9 import withLocalTmpDir from 'with-local-tmp-dir'; 10 10 import {readdirSync,} from 'node:fs'; 11 11 ··· 49 49 }) 50 50 51 51 it('does not throw when a valid level is given', function () { 52 - for (const level of logLevels) { 52 + for (const level of LOGLEVELS) { 53 53 expect(() => buildParsedLogOptions({level})).to.not.throw; 54 54 } 55 55 })