Output Targets
By default mime-logger writes to the console. You can redirect to a file, a custom function, or any combination of the above.
Console output
Section titled “Console output”The default. No configuration needed:
const logger = new Logger("app");// equivalent to:const logger = new Logger("app", { output: "console" });File output
Section titled “File output”Pass a FileOutputOptions object to write to a file. The path supports time-based
tokens so each run (or each hour/day) gets its own file.
import Logger, { type FileOutputOptions } from "mime-logger";
const fileOut: FileOutputOptions = { type: "file", path: "./logs/app-{year}-{month}-{day}.log",};
const logger = new Logger("app", { output: fileOut });Path tokens
Section titled “Path tokens”| Field | Type | Required | Description |
|---|---|---|---|
{year} | string | optional | Four-digit year, e.g. 2025. |
{month} | string | optional | Two-digit month, e.g. 05. |
{day} | string | optional | Two-digit day of month. |
{date} | string | optional | Full ISO date, e.g. 2025-05-15. |
{hour} | string | optional | Two-digit hour (24 h). |
{minutes} | string | optional | Two-digit minutes. |
{seconds} | string | optional | Two-digit seconds. |
{ms} | string | optional | Three-digit milliseconds. |
File streams are opened on first write and kept open for the process lifetime.
Custom output function
Section titled “Custom output function”Provide a function to send log lines anywhere — a remote sink, a queue, an in-memory buffer for tests, etc.
const logs: string[] = [];
const logger = new Logger("app", { output: (message, obj) => { logs.push(message); },});The callback signature:
(message: string, obj: FormatObject) => voidmessage is the fully formatted string (after format runs). obj is the raw
FormatObject if you need the structured data.
Multiple outputs
Section titled “Multiple outputs”Pass an array to write to several targets at once:
import Logger, { Formats } from "mime-logger";
const logger = new Logger("app", { format: Formats.json, output: [ "console", { type: "file", path: "./logs/{year}-{month}-{day}.log" }, ],});Every target receives the same formatted message.
