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.
Creating a child
Section titled “Creating a child”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(name: string): MimeLoggerReturns a new MimeLogger instance. The child’s name is parent/child. If the parent
has no name, the child’s name is just name.
Name hierarchy
Section titled “Name hierarchy”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.
Inheriting options
Section titled “Inheriting options”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 formatconst db = app.child("database");
// override to pretty for this child onlyconst debug = new Logger("app/debug", { format: Formats.pretty });