Skip to content

Getting Started

mime-logger ships ESM and CJS and works with TypeScript out of the box.

import Logger from "mime-logger";
const logger = new Logger();

Pass a name to identify which part of your app produced each log line.

const db = new Logger("database");
const http = new Logger("http");
db.info("Connected");
http.info("Listening on port 3000");
Named loggers output

Without a name the parenthetical is omitted:

const logger = new Logger();
logger.info("Hello");
// [12:34:56.123] INFO: Hello

Use %s as a placeholder to interpolate values into the message. Multiple placeholders are replaced left-to-right.

logger.info("User %s connected from %s", "alice", "192.168.1.1");
logger.warn("Retrying in %s ms (attempt %s of %s)", 500, 2, 3);
Interpolation output
new MimeLogger(name?: string, opts?: LoggerOptions)
FieldTypeRequiredDescription
namestringoptionalLogger name. Shown in parentheses in every log line.
opts.formatstring | FormatFnoptionalOutput format. Defaults to the pretty preset.
opts.outputOutputTarget | OutputTarget[]optionalWhere to send logs. Defaults to console.

See Formats and Output Targets for full configuration options.