Getting Started
Import styles
Section titled “Import styles”mime-logger ships ESM and CJS and works with TypeScript out of the box.
import Logger from "mime-logger";const logger = new Logger();import { MimeLogger } from "mime-logger";const logger = new MimeLogger();const { MimeLogger } = require("mime-logger");const logger = new MimeLogger();Named loggers
Section titled “Named loggers”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");
Without a name the parenthetical is omitted:
const logger = new Logger();logger.info("Hello");// [12:34:56.123] INFO: HelloLogging with arguments
Section titled “Logging with arguments”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);
Constructor
Section titled “Constructor”new MimeLogger(name?: string, opts?: LoggerOptions)| Field | Type | Required | Description |
|---|---|---|---|
name | string | optional | Logger name. Shown in parentheses in every log line. |
opts.format | string | FormatFn | optional | Output format. Defaults to the pretty preset. |
opts.output | OutputTarget | OutputTarget[] | optional | Where to send logs. Defaults to console. |
See Formats and Output Targets for full configuration options.
