Skip to content

About

Shared pino-based logging packages for X1 Labs TypeScript services

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ts-logging-common

Shared pino-based logging packages for X1 Labs TypeScript services.

Packages

Package Description Peer Dependencies
@x1-labs/logging Pino logger factory (Node.js + browser) pino-pretty (optional)
@x1-labs/logging-nestjs NestJS integration module nestjs-pino, @nestjs/common, pino-pretty (optional)
@x1-labs/logging-express Express pino-http middleware express, pino-http, pino-pretty (optional)
@x1-labs/logging-bun Bun.serve access logging middleware pino-pretty (optional)

Installation

# Core (any Node.js or browser project)
npm install @x1-labs/logging

# NestJS projects
npm install @x1-labs/logging-nestjs nestjs-pino@^5 @nestjs/common

# Express projects
npm install @x1-labs/logging-express pino-http express

# Bun.serve projects
npm install @x1-labs/logging-bun

# Optional: pretty-printed dev output
npm install -D pino-pretty

Usage

Basic logger

import { createLogger } from '@x1-labs/logging';

const logger = createLogger({ name: 'my-service' });
logger.info('Server started');
logger.debug({ port: 3000 }, 'Listening');

Express middleware

import express from 'express';
import { createExpressLogger } from '@x1-labs/logging-express';

const app = express();
app.use(createExpressLogger({ level: 'debug' }));

Bun.serve

import { createBunLogger } from '@x1-labs/logging-bun';

const { logger, wrapFetch } = createBunLogger({ name: 'api' });

Bun.serve({
  port: 3000,
  fetch: wrapFetch(async (req) => {
    req.log.info({ userId: 42 }, 'handling request');
    return new Response('ok');
  }),
});

logger.info({ port: 3000 }, 'API server listening');

Produces the same access log records as @x1-labs/logging-express.

NestJS module

import { Module } from '@nestjs/common';
import { createNestLoggerModule } from '@x1-labs/logging-nestjs';

@Module({
  imports: [createNestLoggerModule({ level: 'info' })],
})
export class AppModule {}

nestjs-pino 3, 4 and 5 work. On NestJS 11.0.8 or later, use nestjs-pino 5. With 4 and a global prefix (app.setGlobalPrefix('v1')), NestJS logs Unsupported route path: "/v1/*" at startup. Version 5 uses the new route syntax, and also logs requests to the prefix root (/v1).

nestjs-pino 5.2.1 and later ship separate CommonJS and ESM builds. This package is CommonJS, so the app must load nestjs-pino as CommonJS too (a NestJS app built with nest build does). An ESM app gets a second copy of nestjs-pino, and app.get(Logger) fails with Nest could not find Logger element.

Configuration

All packages share the same environment-driven defaults:

Variable Effect Default
LOG_LEVEL Set log level (trace, debug, info, warn, error) info
LOG_FORMAT Set to json for structured JSON output pretty (pino-pretty)
LOG_OMIT_FIELDS Comma-separated base fields to omit (e.g., pid,hostname) pid,hostname
LOG_TIMESTAMP Set to false to omit timestamps from log messages true
NODE_ENV When development, default level becomes debug —

To include all default Pino fields (pid, hostname), set LOG_OMIT_FIELDS=none.

Options passed to createLogger(), createExpressLogger(), or createNestLoggerModule() override environment variables.

Browser support

@x1-labs/logging ships a browser entry point ("browser" field in package.json). Bundlers like webpack and Turbopack automatically use it. The browser build:

  • Uses pino's built-in browser mode (pino/browser.js)
  • Maps log levels to console methods
  • Outputs structured objects (browser: { asObject: true })
  • Skips Node-only features (transports, pino-pretty)

No configuration needed — import { createLogger } from '@x1-labs/logging' works in both environments.

Development

bun install              # Install dependencies
bun run build            # Build all packages
bun run check            # Format + lint + typecheck
bun run bump 0.1.5       # Bump all package versions
bun run publish-all      # Build + publish all packages to npm

License

MIT

About

Shared pino-based logging packages for X1 Labs TypeScript services

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages