Skip to Content
HeronJS v4 is now available.
Versionv4UtilitiesLogging

Logging

Create an application logger with Logger from @heronjs/common. Message text is readable, and structured data and error redaction is off by default since 4.3.0.

import {Logger} from '@heronjs/common'; const logger = new Logger(); logger.info({message: 'Order processing completed', data: {count: 3}});

info, warning, error, fatal, and trace accept {message, data?}. Configure a component with new Logger({target: 'orders', options: {redact: true}}); new Logger() retains the default component and settings.

logger.log({message: 'Order accepted', data: {count: 1}}) writes text and optional data. For a structured envelope, use logger.log({message: {module: 'orders', status: 'ready', data: {count: 1}}}); envelope data belongs inside message. No event registration helper is needed.

Enable data redaction

import {Logger, DEFAULT_LOG_REDACTION} from '@heronjs/common'; const logger = new Logger({options: {redact: true}}); // Equivalent explicit preset: const operationalLogger = new Logger({options: {redact: DEFAULT_LOG_REDACTION}}); logger.info({message: 'Order processing completed', data: {count: 3, password: 'example'}});

The default preset retains operational fields such as counts, durations and status codes while removing private data and error details. Message text stays readable even with redaction enabled: keep credentials and private payloads out of message strings.

For selected fields, supply paths such as new Logger({options: {redact: ['data.password']}}). Choose rules appropriate to the data your application logs. Telemetry, worker output and messaging callback protections have their own behavior; application logger configuration does not replace those controls.

Output and levels

Logging defaults to info. Set LOG_LEVEL=warn or LOG_LEVEL=silent to reduce output. Terminals use readable rows; redirected output uses JSON. Stdio applications route framework logs to stderr automatically. Startup diagnostics include application and adapter information.

Startup output in 4.6.0

Startup logs show the application banner and registered resources. Names of components such as modules, providers and controllers are grouped into one comma-separated row per kind. Lifecycle progress messages and registration count summaries are no longer included.

Handler mappings and protocol resources remain individual rows. Command/query and event entries identify their handlers. Worker task entries identify the module, request, token and handler. Protocol entries show details such as methods, paths, operations, topics and declared access policies.

For an application registering order providers and a protected HTTP route, terminal output can look like this:

[14:21:59.396] INFO (Core): [Module] { AppModule } [14:21:59.396] INFO (Core): [Provider] { OrderService, InventoryService } [14:21:59.397] INFO (Core): [Command] { CreateOrder · handler CreateOrderHandler } [14:21:59.398] INFO (HttpAdapter): [Resource] { GET · /orders/ · Protected }

Use these rows to check which components and endpoints your application registered. Resource methods, paths and access labels use middle-dot separators in terminal output. Redirected output retains structured JSON fields, and log-level filtering still applies. Your application logger calls and redaction settings continue to work as described above.

Operational diagnostics

Framework diagnostics identify the failed operation and suggest checks for dependency injection, SQL connections, services, events, caches, messaging, SSE, or worker cleanup. Recognized SQL connection and authentication failures include guidance for checking configuration. Raw error details remain subject to framework redaction, and suppressed worker output stays suppressed. Application logger redaction remains opt-in.

Last updated on