Skip to content

gaslamp


Class: CategoryLogger

A logger wrapper that automatically adds a category to all log entries.

Provides a convenient way to log with a consistent category without specifying it in every log call. Useful for organizing logs by feature (auth, database, api, etc.) when you want all logs for that feature to share the same category.

Remarks

CategoryLogger wraps the global singleton logger from getLogger(). It does not create a separate logger — all logs still accumulate in the same global instance, just with the category pre-filled.

Since

0.42.0

Example

TypeScript
const authLogger = getCategoryLogger('auth');
const dbLogger = getCategoryLogger('database');

authLogger.info('User login');  // category: 'auth'
dbLogger.error('Connection timeout');  // category: 'database'

Constructors

Constructor

new CategoryLogger(logger, category): CategoryLogger

Constructs a CategoryLogger wrapping the given logger.

Parameters

logger

AfterGlow

The underlying AfterGlow logger instance

category

string

The category to add to all log entries

Returns

CategoryLogger

Methods

log()

log(message, options?): void

Logs a message with a specific log level and this logger's category.

Parameters

message

string

Log message

options?

Omit\<GlowOptions, "category"> = {}

Optional log options (category is added automatically)

Returns

void

Example

TypeScript
const authLogger = getCategoryLogger('auth');
authLogger.log('Token refreshed', { level: 'debug' });
authLogger.log('Login failed', { level: 'error', values: ['user123'] });

info()

info(message, options?): void

Logs an info-level message with this logger's category.

Parameters

message

string

Log message

options?

Omit\<GlowOptions, "level" | "category"> = {}

Optional log options (category is added automatically)

Returns

void

Example

TypeScript
const authLogger = getCategoryLogger('auth');
authLogger.info('User logged in', { values: ['user123'] });

warn()

warn(message, options?): void

Logs a warning-level message with this logger's category.

Parameters

message

string

Log message

options?

Omit\<GlowOptions, "level" | "category"> = {}

Optional log options (category is added automatically)

Returns

void

Example

TypeScript
const apiLogger = getCategoryLogger('api');
apiLogger.warn('Rate limit exceeded', { values: [100, 'req/min'] });

error()

error(message, options?): void

Logs an error-level message with this logger's category.

Parameters

message

string

Log message

options?

Omit\<GlowOptions, "level" | "category"> = {}

Optional log options (category is added automatically)

Returns

void

Example

TypeScript
const dbLogger = getCategoryLogger('database');
dbLogger.error('Query timeout', { values: ['SELECT * FROM users'] });

debug()

debug(message, options?): void

Logs a debug-level message with this logger's category.

Parameters

message

string

Log message

options?

Omit\<GlowOptions, "level" | "category"> = {}

Optional log options (category is added automatically)

Returns

void

Example

TypeScript
const authLogger = getCategoryLogger('auth');
authLogger.debug('Token validation started', { values: ['tok_abc123'] });