@triplef/core-logger
v0.1.1
Published
A lightweight NestJS LoggerService backed by pino — structured logging with inline context rendering and error-stack preservation.
Readme
@triplef/core-logger
A lightweight NestJS LoggerService backed by pino — structured logging with inline context rendering and error-stack preservation.
This library is **ESM-only** and does not support CommonJS.Your project must use ES modules.
Features
- NestJS-native — implements
LoggerService(log,error,warn,debug,verbose,fatal,setLogLevels); the service owns the pino client and delegates to it. - Inline context — the trailing context string NestJS's static
Loggerappends renders as[Context] messagein pretty mode and stays a structuredcontextfield in JSON mode. - Error preservation — Error instances flow through pino's
errserializer (type, message, stack); a bareerror(message, stack, context)stack string is kept verbatim understack. - pino object-first form —
log({ requestId }, 'request received')merges bindings with the NestJS context.
Call shapes
| Call | Pino call |
| ---------------------------------- | --------------------------------------------- |
| log('hello') | info('hello') |
| log('hello', 'Ctx') | info({ context: 'Ctx' }, 'hello') |
| log({ requestId }, 'msg', 'Ctx') | info({ requestId, context: 'Ctx' }, 'msg') |
| log('msg', { requestId }, 'Ctx') | info({ requestId, context: 'Ctx' }, 'msg') |
| error(err, 'Ctx') | error({ err, context: 'Ctx' }, err.message) |
| error('msg', err, 'Ctx') | error({ err, context: 'Ctx' }, 'msg') |
| error('msg', stack, 'Ctx') | error({ stack, context: 'Ctx' }, 'msg') |
| verbose(msg) | trace(msg) |
Installation
pnpm add @triplef/core-loggerUsage
Module setup
The library ships no env-driven config — supply the pino LoggerOptions
through a factory, and validate them with the exported CoreLoggerSchema.
import { CoreLoggerModule, CoreLoggerSchema } from '@triplef/core-logger';
import { ValidateReturnValue } from '@triplef/config-factory/validate-return-value';
@Module({
imports: [
CoreLoggerModule.registerAsync({
global: true,
inject: [MyLoggerConfigService],
useFactory: (config: MyLoggerConfigService) => config.options,
}),
],
})
export class AppModule {}Bootstrap
import { CoreLoggerService } from '@triplef/core-logger';
const app = await NestFactory.create(AppModule, { bufferLogs: true });
app.useLogger(app.get(CoreLoggerService));