Skip to content

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.

The default. No configuration needed:

const logger = new Logger("app");
// equivalent to:
const logger = new Logger("app", { output: "console" });

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 });
FieldTypeRequiredDescription
{year}stringoptionalFour-digit year, e.g. 2025.
{month}stringoptionalTwo-digit month, e.g. 05.
{day}stringoptionalTwo-digit day of month.
{date}stringoptionalFull ISO date, e.g. 2025-05-15.
{hour}stringoptionalTwo-digit hour (24 h).
{minutes}stringoptionalTwo-digit minutes.
{seconds}stringoptionalTwo-digit seconds.
{ms}stringoptionalThree-digit milliseconds.

File streams are opened on first write and kept open for the process lifetime.

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) => void

message is the fully formatted string (after format runs). obj is the raw FormatObject if you need the structured data.

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.