Logging Methods

Hive Logger provides convenient methods for each log level: trace, debug, info, warn, and error.

All logging methods support flexible argument patterns for structured and formatted logging:

No Arguments

Logs an empty message at the specified level.

log.debug();
2025-04-10T14:00:00.000Z DBG

Attributes Only

Logs structured attributes without a message.

log.info({ hello: "world" });
2025-04-10T14:00:00.000Z INF
  hello: "world"

Message with Interpolation

Logs a formatted message, similar to printf-style formatting. Read more about it in the Message Formatting section.

log.warn("Hello %s!", "World");
2025-04-10T14:00:00.000Z WRN Hello World!

Attributes and Message (with interpolation)

Logs structured attributes and a formatted message. The attributes can be anything object-like, including classes.

const err = new Error("Something went wrong!");
log.error(err, "Problem occurred at %s", new Date());
2025-04-10T14:00:00.000Z ERR Problem occurred at Thu Apr 10 2025 14:00:00 GMT+0200 (Central European Summer Time)
  stack: "Error: Something went wrong!
      at <anonymous> (/projects/example.js:2:1)"
  message: "Something went wrong!"
  name: "Error"
  class: "Error"

Message Formatting

The Hive Logger uses the quick-format-unescaped library to format log messages that include interpolation (e.g., placeholders like %s, %d, etc.).

import { Logger } from "@graphql-hive/logger";

const log = new Logger();

log.info("hello %s %j %d %o", "world", { obj: true }, 4, { another: "obj" });

Outputs:

2025-04-10T14:00:00.000Z INF hello world {"obj":true} 4 {"another":"obj"}

Available interpolation placeholders are:

  • %s - string
  • %d and %f - number with(out) decimals
  • %i - integer number
  • %o,%O and %j - JSON stringified object
  • %% - escaped percentage sign