Skip to main content

Recipes

Structured (JSON) logging

{
logs: {
type: 'json',
level: 'info'
}
}

QJSONLogger emits structured JSON with level and message, plus any extra metadata fields passed to the logger methods.

Selecting a logger directly

import { getLoggerByType, QLoggerType } from '@quik/logging';
import { QLogLevel } from '@quik/core';

const logger = getLoggerByType(QLoggerType.JSON, QLogLevel.INFO);
logger.info('standalone script started');

Useful for CLI scripts or workers that run outside the normal bootstrap pipeline and still want a configured logger instance.

Logging method execution with decorators

import { LoggingDecorators } from '@quik/logging';
import { QObject } from '@quik/core';

class OrderService extends QObject {
@LoggingDecorators.AsyncLog('OrderService')
async placeOrder(orderId: string) {
// ...
}

@LoggingDecorators.AsyncTrackPerformance('OrderService')
async computeTotals(orderId: string) {
// ...
}
}

Log/AsyncLog emit verbose entry/exit/argument/result logs; TrackPerformance/AsyncTrackPerformance measure execution time and memory usage via perf_hooks and log the result at verbose level. All four accept an optional prefix used to namespace the log lines.

Disabling logging entirely

{
logs: {
enabled: false
}
}

Setting logs.enabled to false forces QLoggerType.NO_LOGGER regardless of logs.type, discarding all log output through QNoLogger.