API Reference
MimeLogger class
Section titled “MimeLogger class”import { MimeLogger } from "mime-logger";import Logger from "mime-logger"; // default export, same classConstructor
Section titled “Constructor”new MimeLogger(name?: string, opts?: LoggerOptions)| Field | Type | Required | Description |
|---|---|---|---|
name | string | optional | Logger name. Appears in log output as (name). |
opts | LoggerOptions | optional | Format and output options. |
Instance methods
Section titled “Instance methods”| Field | Type | Required | Description |
|---|---|---|---|
info(message, ...args) | void | optional | Log at INFO level. |
warn(message, ...args) | void | optional | Log at WARN level. |
error(message, ...args) | void | optional | Log at ERROR level. |
log(level, message, args) | void | optional | Low-level log. args is an array. |
child(name) | MimeLogger | optional | Create a child logger. Name is appended as parent/child. |
write(message, ...args) | void | optional | Write a formatted line to stdout. No level badge. |
promisesWrite(message, level, ...promises) | Promise<void> | optional | Resolve promises inline in log output. Use %p as placeholder. |
promisesWrite
Section titled “promisesWrite”Awaits each promise and writes its resolved value where %p appears in the message.
Throws if the message has no %p. (I admits this is a bit useless)
await logger.promisesWrite( "User: %p, Role: %p", LogLevel.INFO, fetchUser(id), fetchRole(id),);// [12:34:56.789] INFO (app): User: alice, Role: adminLoggerOptions
Section titled “LoggerOptions”interface LoggerOptions { format?: string | FormatFn; output?: OutputTarget | OutputTarget[];}LogLevel
Section titled “LogLevel”enum LogLevel { INFO = "info", WARN = "warn", ERROR = "error",}FormatObject
Section titled “FormatObject”interface FormatObject { message: string; name?: string; timestamp: Date; level: LogLevel; args: any[];}FormatFn
Section titled “FormatFn”type FormatFn = (obj: FormatObject, colors: ColorHelpers) => string;OutputTarget
Section titled “OutputTarget”type OutputTarget = | "console" | FileOutputOptions | ((message: string, obj: FormatObject) => void);FileOutputOptions
Section titled “FileOutputOptions”interface FileOutputOptions { type: "file"; path: string; // supports {year} {month} {day} {date} {hour} {minutes} {seconds} {ms}}ColorHelpers
Section titled “ColorHelpers”interface ColorHelpers { red: (s: string) => string; yellow: (s: string) => string; blue: (s: string) => string; green: (s: string) => string; cyan: (s: string) => string; magenta: (s: string) => string; gray: (s: string) => string; bold: (s: string) => string; dim: (s: string) => string;}CallerInfoOptions
Section titled “CallerInfoOptions”interface CallerInfoOptions { skipFrames?: number; additionalSkip?: RegExp;}Formats object
Section titled “Formats object”import { Formats } from "mime-logger";| Field | Type | Required | Description |
|---|---|---|---|
Formats.pretty | FormatFn | optional | Default. Colored timestamp, level badge, name, message. |
Formats.minimal | FormatFn | optional | Compact. Level padded to 5 chars, dimmed name, plain message. |
Formats.detailed | FormatFn | optional | Caller location + ISO timestamp prepended. |
Formats.json | FormatFn | optional | Structured JSON output: { timestamp, level, name, message }. |
Utilities
Section titled “Utilities”getLevelString
Section titled “getLevelString”Returns a colored ANSI string for the given level — e.g. "INFO" in green.
import { getLevelString } from "mime-logger";getLevelString(LogLevel.WARN); // yellow "WARN"getCallerInfo
Section titled “getCallerInfo”Extracts stack frame information for the calling site. Used internally by
Formats.detailed and {file} / {line} format tokens.
import { getCallerInfo } from "mime-logger";
const { file, line, function: fn, caller } = getCallerInfo({ skipFrames: 1 });colors
Section titled “colors”The ColorHelpers instance used by all built-in presets.
import { colors } from "mime-logger";console.log(colors.green("ok"));