ForgeKit Stable v1.0 is officially released. Upgrade now for zero-assertions DB compilation. Read Release Notes
Docs Nav

@forgekit/logger

@forgekit/logger is a zero-overhead structured JSON logger specifically optimized for serverless edge runtimes, Cloudwatch, and Datadog aggregations.

Initialization Setup

To load the logger plugin:

import { ForgeApp } from '@forgekit/core';
import { logger } from '@forgekit/logger';

const app = new ForgeApp();

app.use(
	logger({
		level: 'info', // 'debug' | 'info' | 'warn' | 'error'
		redact: ['password', 'sessionToken', 'authorization']
	})
);

Log Output Levels

Structured log methods output standardized JSON blobs to standard out:

// 1. Info logs
app.logger.info({ userId: 'usr_100' }, 'User logged in successfully');

// Output JSON:
// {"level":"info","time":1678882900,"msg":"User logged in successfully","userId":"usr_100"}

// 2. Warn logs
app.logger.warn({ path: '/admin' }, 'Deprecated route accessed');

// 3. Error logs
try {
	throw new Error('Database connection timeout');
} catch (err) {
	app.logger.error({ err }, 'Failed to fetch settings');
}

Contextual Context Hooks

Bind key context parameters (like tracing request IDs) once to automatically append them to subsequent log statements:

const requestLogger = app.logger.child({ requestId: 'req_xyz_999' });

requestLogger.info('Request started');
// Logs contain: "requestId":"req_xyz_999"