Logging
AntelopeJS logging. Severity levels, named channels, and the logging section of antelope.config.ts that filters and formats the output.
Severity levels
AntelopeJS defines five severity levels, each with a numeric value. A higher value means a more severe message. The project configuration sets a minimum level per channel.
| Level | Value | Description |
|---|---|---|
| ERROR | 40 | Errors that need immediate attention. |
| WARN | 30 | Potential issues that may need investigation. |
| INFO | 20 | General operational information. |
| DEBUG | 10 | Detailed information for development. |
| TRACE | 0 | Fine-grained tracing for deep debugging. |
The values are also available as the Logging.Level enum.
Global logging functions
The Logging namespace has one function per severity level. Each function writes to the main channel.
import { Logging } from "@antelopejs/interface-core/logging";
declare const error: unknown;
declare const data: unknown;
Logging.Error("Something failed:", error);
Logging.Warn("Deprecated feature used");
Logging.Info("Server started on port", 3000);
Logging.Debug("Request payload:", data);
Logging.Trace("Entering function processUser");
Each function accepts any number of arguments of any type, as console.log does. When module tracking is on, the core tags each entry with the module that produced it.
Custom channels
A named channel groups logs by subsystem. Create one with new Logging.Channel(name). A channel has the same five functions as the namespace, and the configuration filters each channel separately.
import { Logging } from "@antelopejs/interface-core/logging";
declare const error: unknown;
declare const headers: Record<string, string>;
const httpLog = new Logging.Channel("http");
httpLog.Info("GET /api/users - 200");
httpLog.Error("POST /api/users - 500:", error);
httpLog.Debug("Request headers:", headers);
A channel name can be any string. Name the channel after the subsystem that writes to it, such as http, database, auth, or scheduler. Each channel can have its own minimum level in the configuration.
Writing to custom levels
Logging.Write() logs at any numeric level. Use it when the five built-in levels are not fine-grained enough.
import { Logging } from "@antelopejs/interface-core/logging";
Logging.Write(25, "custom-channel", "Custom level message");
The first argument is the numeric level, the second is the channel name, and the remaining arguments form the message. The message appears only if the channel's minimum level is at or below the given level. A channel object has its own Write(level, ...args), which writes to that channel.
Log configuration
The logging key of antelope.config.ts sets which modules and channels print, the minimum level per channel, and the date format.
{
logging: {
enabled: true,
moduleTracking: {
enabled: true,
includes: ["my-module"],
excludes: ["noisy-module"]
},
channelFilter: {
"main": "info",
"http": 10,
"db:*": "warn"
},
dateFormat: "yyyy-MM-dd HH:mm:ss"
}
}
enabled defaults to true. With enabled: false, the core prints no log lines.
The core checks the logging section when it loads the configuration. enabled and moduleTracking.enabled take booleans, includes and excludes take lists of strings, each channelFilter level takes a name or a number, and formatter values and dateFormat take strings. A value of another type stops the load with an error that names the field. See field checks at load.
Module tracking
Module tracking is off by default. With moduleTracking.enabled: true, the core tags each entry with the module that produced it and shows the tag as (module-name). The includes and excludes lists apply only while tracking is on.
The core always hides a module listed in excludes. When includes is not empty, the core shows only the modules it lists. With both lists set, a module must be in includes and absent from excludes to print.
The core attributes logs that the framework itself writes, rather than one of your modules, to the module name core. Filter core like any other module. Add "core" to excludes to hide framework diagnostics, or list it in includes next to your own modules to keep them.
{
logging: {
moduleTracking: {
enabled: true,
includes: ["my-module", "core"]
}
}
}
If you set includes without core, the core hides its own diagnostics, such as missing interface providers and shutdown failures.
Channel filtering
channelFilter sets the minimum level per channel. Give the level as a name ("info", "debug", case-insensitive) or as a number. The core drops every message below the channel's level without a notice.
A key matches the channel name exactly, and an exact match wins. A key that ends in * is a prefix wildcard, so "db:*" matches every channel whose name starts with db:. When several wildcards match, the longest prefix wins, and "*" alone matches every channel. A channel that no key matches uses the info level. A level string that is neither a level name nor a number counts as warn.
The top-level Logging.Error, Logging.Warn, Logging.Info, Logging.Debug, and Logging.Trace functions write to the channel named main. Set their level with a "main" key or a "*" wildcard.
Date format
dateFormat sets how the date of each line prints. The default is "yyyy-MM-dd HH:mm:ss", which an empty string also selects. The core formats the date in the local timezone and supports these tokens:
| Token | Value |
|---|---|
yyyy, yy | Year, four or two digits |
MM, M | Month, padded or not |
dd, d | Day of the month, padded or not |
HH, H | Hour from 0 to 23, padded or not |
mm, m | Minutes, padded or not |
ss, s | Seconds, padded or not |
SSS | Milliseconds, three digits |
The core replaces only the first occurrence of each token in the format string.
Start with "main": "info". Lower a channel to "debug" only while you troubleshoot that subsystem, so the output stays readable during normal operation.