API Reference
Default singleton
Section titled “Default singleton”import { wiz } from "@gouranga_samrat/log-wiz";A pre-built Wiz instance with auto-detected defaults. Use this for simple scripts and small apps.
new Wiz(config?)
Section titled “new Wiz(config?)”Creates a new independent logger instance.
import { Wiz } from "@gouranga_samrat/log-wiz";
const logger = new Wiz(config?: WizConfig);Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
config | WizConfig | No | Instance configuration. See Configuration for all options. |
Example:
const logger = new Wiz({ scope: "api", level: "debug", file: { dir: "./logs", maxFiles: 7 },});Log methods
Section titled “Log methods”All six log methods share the same signature:
logger.trace(message: string, options?: LogCallOptions): voidlogger.debug(message: string, options?: LogCallOptions): voidlogger.info (message: string, options?: LogCallOptions): voidlogger.warn (message: string, options?: LogCallOptions): voidlogger.error(message: string, options?: LogCallOptions): voidlogger.fatal(message: string, options?: LogCallOptions): voidParameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Primary human-readable log message |
options.meta | Record<string, unknown> | No | Structured metadata. Deep-cloned and PII-masked before output. |
options.error | Error | No | Error object. Stack trace is parsed into structured StackFrame[]. |
options.correlationId | string | No | Overrides the instance-level correlationId for this call only. |
Examples
Section titled “Examples”// Message onlylogger.info("Server started");
// With metadatalogger.info("Request completed", { meta: { method: "POST", path: "/users", statusCode: 201, durationMs: 14 },});
// With errorlogger.error("Database query failed", { error: new Error("ECONNREFUSED"), meta: { host: "db.internal", port: 5432 },});
// With per-call correlationIdlogger.info("Processing item", { correlationId: job.id, meta: { itemId: item.id, queue: "high-priority" },});
// All options combinedlogger.fatal("Critical failure", { correlationId: "req-abc-123", meta: { component: "payment-processor", retries: 3 }, error: new TypeError("Cannot read properties of null"),});logger.setConfig(partial)
Section titled “logger.setConfig(partial)”Merges a partial config update into the running instance at runtime.
logger.setConfig(updates: Partial<WizConfig>): voidRebuilds transports automatically when format or file changes.
// Change level at runtimelogger.setConfig({ level: "debug" });
// Switch to JSON formatlogger.setConfig({ format: "json" });
// Disable file outputlogger.setConfig({ file: false });
// Add masked keyslogger.setConfig({ maskedKeys: ["sessionToken", "internalId"] });logger.flush()
Section titled “logger.flush()”Synchronously flushes all buffered entries to their transports.
logger.flush(): voidCall this before a graceful shutdown to ensure no buffered file entries are lost.
process.on("SIGTERM", async () => { logger.flush(); // synchronous flush await logger.close(); // then async close process.exit(0);});logger.close()
Section titled “logger.close()”Flushes all buffers and asynchronously releases all transport resources (file handles, timers, etc.).
logger.close(): Promise<void>Always await this before process.exit() when using the file transport.
await logger.close();LogCallOptions
Section titled “LogCallOptions”interface LogCallOptions { readonly correlationId?: string; readonly meta?: Record<string, unknown>; readonly error?: Error;}wiz.config() — global singleton helper
Section titled “wiz.config() — global singleton helper”The default wiz singleton can be reconfigured at any time:
import { wiz } from "@gouranga_samrat/log-wiz";
wiz.setConfig({ level: "debug", format: "json" });