Skip to content

Documentation / @agentick/kernel / Logger

Variable: Logger

const Logger: object

Defined in: kernel/src/logger.ts:365

Logger singleton for Agentick applications.

Provides structured logging with automatic context injection from the current execution context (via AsyncLocalStorage).

Type Declaration

level

Get Signature

get level(): LogLevel

Get the current log level.

Returns

LogLevel

child()

child(bindings): KernelLogger

Create a child logger with custom bindings.

Parameters

bindings

Record<string, unknown>

Key-value pairs to include in every log

Returns

KernelLogger

Child logger with bindings

Example

typescript
const requestLog = Logger.child({ request_id: req.id });
requestLog.info('Handling request');

configure()

configure(config): void

Configure the global logger. Should be called once at application startup.

Parameters

config

LoggerConfig

Logger configuration

Returns

void

Example

typescript
Logger.configure({
  level: process.env.LOG_LEVEL ?? 'info',
  transport: {
    targets: [
      { target: 'pino-pretty', options: { colorize: true } },
      { target: 'pino/file', options: { destination: './logs/app.log' } },
    ],
  },
});

create()

create(config?): KernelLogger

Create a standalone logger instance with custom config. Does not affect the global logger.

Parameters

config?

LoggerConfig = {}

Logger configuration

Returns

KernelLogger

New logger instance

Example

typescript
const auditLog = Logger.create({
  level: 'info',
  transport: { target: 'pino/file', options: { destination: './audit.log' } },
});

for()

for(nameOrComponent): KernelLogger

Create a child logger scoped to a component or name.

Parameters

nameOrComponent

Component name or object (uses constructor.name)

string | object

Returns

KernelLogger

Child logger with component binding

Example

typescript
// With string name
const log = Logger.for('CalculatorTool');

// With object (uses class name)
class MyAgent {
  private log = Logger.for(this);
}

get()

get(): KernelLogger

Get the global logger instance. Context is automatically injected into every log.

Returns

KernelLogger

KernelLogger instance

Example

typescript
const log = Logger.get();
log.info('Processing', { items: 5 });
// Output includes executionId, userId, trace_id, etc.

isLevelEnabled()

isLevelEnabled(level): boolean

Check if a level is enabled.

Parameters

level

LogLevel

Log level to check

Returns

boolean

true if the level is enabled

reset()

reset(): void

Reset the global logger (mainly for testing).

Returns

void

setLevel()

setLevel(level): void

Set the log level at runtime.

Parameters

level

LogLevel

New log level

Returns

void

Example

typescript
// Configure at app startup
Logger.configure({ level: 'debug' });

// Get logger (context auto-injected)
const log = Logger.get();
log.info('Request received');

// Create child logger for a component
const componentLog = Logger.for('MyComponent');
componentLog.debug('Initializing');

// Or from an object (uses constructor name)
class MyTool {
  private log = Logger.for(this);
}

Released under the ISC License.