Class: PinoLogger
Defined in: src/observability/logger.ts:205
Pino-based structured logger implementing ILogger.
Remarks
Provides structured JSON logging with:
- OpenTelemetry trace context injection (trace_id, span_id)
- Sensitive data redaction (passwords, tokens, API keys)
- Child logger support for request-scoped logging
- Base fields (service, environment, version)
Logs are output to stdout in JSON format for collection by Promtail.
Example
const logger = new PinoLogger({ level: 'info', service: 'chive-appview' });
// Basic logging
logger.info('Server started', { port: 3000 });
// Child logger for request context
const reqLogger = logger.child({ requestId: 'req_123' });
reqLogger.info('Processing request');
// Error logging with stack trace
try {
await riskyOperation();
} catch (error) {
logger.error('Operation failed', error as Error, { operation: 'riskyOp' });
}
See
ILogger for interface contract
Since
0.1.0
Implements
Constructors
new PinoLogger()
new PinoLogger(
options):PinoLogger
Defined in: src/observability/logger.ts:231
Creates a new PinoLogger instance.
Parameters
options
PinoLoggerOptions = {}
Configuration options
Returns
Example
// Production configuration
const logger = new PinoLogger({
level: 'info',
service: 'chive-appview',
environment: 'production',
});
// Development with pretty printing
const devLogger = new PinoLogger({
level: 'debug',
pretty: true,
});
Methods
child()
child(
context):ILogger
Defined in: src/observability/logger.ts:433
Creates a child logger with additional context.
Parameters
context
Readonly
Context to merge into all log entries
Returns
Child logger with merged context
Remarks
Child loggers inherit parent context and add their own. Useful for per-request or per-operation logging. Context is automatically redacted for sensitive fields.
Example
const requestLogger = logger.child({ requestId: 'req_123', userId: 'did:plc:abc' });
requestLogger.info('Processing request');
// Output includes both requestId and userId in every log entry
// Child loggers can be nested
const opLogger = requestLogger.child({ operation: 'indexPreprint' });
opLogger.debug('Starting operation');
// Output includes requestId, userId, and operation
Implementation of
debug()
debug(
message,context?):void
Defined in: src/observability/logger.ts:303
Logs a debug message.
Parameters
message
string
Log message
context?
Readonly<Record<string, unknown>>
Additional context metadata
Returns
void
Remarks
Debug messages are typically disabled in production via LOG_LEVEL. Context is automatically redacted for sensitive fields.
Example
logger.debug('Processing event', { eventType: 'commit', seq: 12345 });
// Output: {"level":"debug","time":"...","msg":"Processing event","eventType":"commit","seq":12345,"trace_id":"..."}
Implementation of
error()
error(
message,error?,context?):void
Defined in: src/observability/logger.ts:386
Logs an error message with optional error object.
Parameters
message
string
Log message
error?
Error
Error object with stack trace
context?
Readonly<Record<string, unknown>>
Additional context metadata
Returns
void
Remarks
Error objects are serialized with their stack traces. Context is automatically redacted for sensitive fields.
Example
try {
await indexPreprint(preprint);
} catch (error) {
logger.error('Failed to index preprint', error as Error, { uri: preprintUri });
}
// Output: {"level":"error","time":"...","msg":"Failed to index preprint","err":{"message":"...","stack":"..."},"uri":"..."}
Implementation of
info()
info(
message,context?):void
Defined in: src/observability/logger.ts:329
Logs an info message.
Parameters
message
string
Log message
context?
Readonly<Record<string, unknown>>
Additional context metadata
Returns
void
Remarks
Standard level for operational messages. Context is automatically redacted for sensitive fields.
Example
logger.info('Indexed preprint', { uri: 'at://did:plc:abc/pub.chive.preprint/123', duration: 150 });
// Output: {"level":"info","time":"...","msg":"Indexed preprint","uri":"at://...","duration":150}
Implementation of
warn()
warn(
message,context?):void
Defined in: src/observability/logger.ts:355
Logs a warning message.
Parameters
message
string
Log message
context?
Readonly<Record<string, unknown>>
Additional context metadata
Returns
void
Remarks
Use for potentially problematic situations that don't prevent operation. Context is automatically redacted for sensitive fields.
Example
logger.warn('Index is stale', { uri: 'at://did:plc:abc/...', staleness: 'high' });
// Output: {"level":"warn","time":"...","msg":"Index is stale","uri":"at://...","staleness":"high"}