Skip to content

Child Loggers

Child loggers let you create scoped sub-loggers that share the parent’s options (format, output targets) while carrying their own name segment.

const app = new Logger("app");
const db = app.child("database");
const query = db.child("query");
app.info("Starting");
db.info("Connected");
query.info("SELECT users");
Child loggers output
child(name: string): MimeLogger

Returns a new MimeLogger instance. The child’s name is parent/child. If the parent has no name, the child’s name is just name.

Names are joined with /, building a breadcrumb trail:

parent → "server"
parent.child(a) → "server/http"
parent.child(b) → "server/db"
http.child(c) → "server/http/middleware"

This makes it easy to filter log output by prefix in any log aggregator.

Children inherit the parent’s format and output. You can override them per-child by passing opts to a new MimeLogger directly:

import Logger, { Formats } from "mime-logger";
const app = new Logger("app", { format: Formats.json });
// inherits JSON format
const db = app.child("database");
// override to pretty for this child only
const debug = new Logger("app/debug", { format: Formats.pretty });