@heyhru/common-util-logger
v0.3.2
Published
Shared logger based on pino, usable on web and server
Downloads
308
Readme
@heyhru/common-util-logger
Shared logger based on pino, usable on both server and browser.
Usage
import { createLogger } from "@heyhru/common-util-logger";
const logger = createLogger({ name: "my-service" });
logger.info("server started");
logger.error({ err }, "request failed");
logger.debug({ userId }, "user login");
// Child logger with bound context
const reqLogger = logger.child({ requestId: "abc-123" });
reqLogger.info("handling request");Options
| Option | Type | Default | Description |
| ------ | ------ | ----------------------------------- | ----------------- |
| name | string | — | Logger name |
| level | string | debug (dev) / info (production) | Minimum log level |
Log Levels
| Level | Value | Usage | | ----- | ----- | ---------------------- | | fatal | 60 | Process about to crash | | error | 50 | Runtime errors | | warn | 40 | Warnings | | info | 30 | General information | | debug | 20 | Debug details | | trace | 10 | Fine-grained tracing |
Environment Behavior
- Development (
NODE_ENV !== 'production'): defaults todebuglevel, usespino-prettyfor colorized output (server only) - Production: defaults to
infolevel, outputs JSON to stdout - Browser: uses
consolemethods, nopino-pretty
