Core Concepts

The building blocks of ZTracer.

Groups

Groups visually separate log categories. Each group can have a background and text color.

const logger = new ZTracer({
  groups: {
    api: { background: "#0d6efd", color: "#fff" },
    db:  { background: "#198754", color: "#fff" }
  }
});
await logger.log("User logged in", { group: "api" });

If a group is not defined, ZTracer renders it with a default gray style. See the API Reference for full group configuration.

Suffixes

A suffix is an optional label appended to the group name. Useful for distinguishing multiple logs in the same group.

await logger.log("Request #1", { group: "api", suffix: "req-1" });
await logger.log("Request #2", { group: "api", suffix: "req-2" });

Console output: api req-1 and api req-2.

Debug Mode

The debug flag controls console output only. Callbacks always run, even when debug: false.

{
  global: {
    debug: false,  // No console output
    callBack: async (data) => { /* still runs */ }
  }
}

This is useful for production telemetry — see the Log Lifecycle page for details.

fromJson()

Logs structured data: arrays as tables (console.table), objects as expandable directories (console.dir).

await logger.fromJson([
  { id: 1, name: "Alice" }
], { group: "db" });

For more examples, visit the Examples page.

time()

Measures execution time of async or sync functions. Each timer gets a unique label.

await logger.time(async () => {
  await fetch("https://api.example.com");
}, { group: "api" });

Log Lifecycle

Every log passes through 4 stages in order:

  1. Console Logger — only if debug: true
  2. Global Callback — if defined
  3. Group Callback — if group exists and has a callback
  4. Specific Callback — if provided in options

For a detailed explanation with examples, see the Log Lifecycle page.

Next: Dive deeper into the Log Lifecycle or explore API Reference.