@barry-rocks/sdk/logging
Structured logging for Node code: createLogger, redaction helpers that
keep secrets out of log lines, flushAll, and setupGracefulShutdown. Logs
are JSON lines that Barry’s tools read back.
import { … } from "@barry-rocks/sdk/logging";Interfaces
Section titled “Interfaces”CreateLoggerOptions
Section titled “CreateLoggerOptions”Properties
Section titled “Properties”LogContext
Section titled “LogContext”Indexable
Section titled “Indexable”[
key:string]:unknown
Logger
Section titled “Logger”Methods
Section titled “Methods”child()
Section titled “child()”child(
context):Logger
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
context |
LogContext |
Returns
Section titled “Returns”debug()
Section titled “debug()”debug(
msg,context?):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
msg |
string |
context? |
LogContext |
Returns
Section titled “Returns”void
error()
Section titled “error()”error(
msg,context?):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
msg |
string |
context? |
LogContext |
Returns
Section titled “Returns”void
flush()
Section titled “flush()”flush():
Promise<void>
Returns
Section titled “Returns”Promise<void>
info()
Section titled “info()”info(
msg,context?):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
msg |
string |
context? |
LogContext |
Returns
Section titled “Returns”void
warn()
Section titled “warn()”warn(
msg,context?):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
msg |
string |
context? |
LogContext |
Returns
Section titled “Returns”void
LogRow
Section titled “LogRow”One parsed log line, as the store holds it.
ts is UNIX SECONDS. pino writes time in MILLISECONDS and every store in
this bag is seconds; getting it wrong puts rows ~56,000 years out, where no
window query will ever see them.
Properties
Section titled “Properties”| Property | Type |
|---|---|
ctx |
string |
id |
string |
level |
number |
msg |
string |
service |
string |
ts |
number |
Type Aliases
Section titled “Type Aliases”LevelName
Section titled “LevelName”LevelName = keyof typeof
LEVEL
The level names an emitter accepts, mapped to the numbers it must write.
LogLevel
Section titled “LogLevel”LogLevel =
"debug"|"info"|"warn"|"error"
Variables
Section titled “Variables”CTX_OMIT
Section titled “CTX_OMIT”
constCTX_OMIT:Set<string>
Fields promoted to columns; the rest stay in ctx.
name duplicates service; time/level/msg are columns; hostname
and pid never varied usefully in practice.
constLEVEL:object
pino numeric levels, named so callers stop writing magic numbers.
Type Declaration
Section titled “Type Declaration”| Name | Type | Default value |
|---|---|---|
debug |
20 |
20 |
error |
50 |
50 |
fatal |
60 |
60 |
info |
30 |
30 |
trace |
10 |
10 |
warn |
40 |
40 |
Functions
Section titled “Functions”createLogger()
Section titled “createLogger()”createLogger(
service,options?):Logger
Create a logger for a service
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
service |
string |
The service name (e.g., “web”, “slack”) |
options? |
CreateLoggerOptions |
Optional configuration |
Returns
Section titled “Returns”A Logger instance
Example
Section titled “Example”import { createLogger } from "./index.js";
const log = createLogger("my-service");log.info("Server started", { port: 3000 });log.error("Request failed", { error: err.message, requestId: "abc" });
// For MCP servers (stdout reserved for protocol):const log = createLogger("mcp-barry", { transport: "stderr" });
// Flush on shutdownprocess.on("SIGTERM", async () => { await log.flush(); process.exit(0);});flushAll()
Section titled “flushAll()”flushAll():
Promise<void>
Flush all pending logs before process exit.
A no-op since the Axiom transport was removed: pino writes to stdout
synchronously, so there is nothing buffered to drain. Kept because
setupGracefulShutdown awaits it and services call that — and because a
future async sink would need exactly this hook back.
Returns
Section titled “Returns”Promise<void>
parseLine()
Section titled “parseLine()”parseLine(
line,service):LogRow|null
Parse one pino line.
Unlike errors.ts’s parser there is no level pre-filter – keeping level 30
is the entire point – so this runs JSON.parse on every line. That is the
cost the offset tracking buys back: a pass sees only new bytes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
line |
string |
service |
string |
Returns
Section titled “Returns”LogRow | null
redact()
Section titled “redact()”redact(
obj):Record<string,unknown>
Logging for anything Barry runs: the Node emitter, and the line format it writes and the logs bag reads back.
Part of the kit, not of the logs bag: every bag and service writes log
lines, and a bag that only wants to write one should not depend on the bag
that collects and stores them. The logs bag keeps the store; Workers code
uses @barry-rocks/sdk/logging/edge.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
obj |
Record<string, unknown> |
Returns
Section titled “Returns”Record<string, unknown>
setupGracefulShutdown()
Section titled “setupGracefulShutdown()”setupGracefulShutdown(
server,log,options?):void
Setup graceful shutdown for a server with proper log flushing
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
server |
{ close: (callback?) => void; } |
The HTTP server to close on shutdown |
server.close |
(callback?) => void |
- |
log |
Logger |
Logger instance for shutdown logging |
options |
{ forceExitTimeout?: number; onShutdown?: () => Promise<void>; } |
Optional configuration |
options.forceExitTimeout? |
number |
- |
options.onShutdown? |
() => Promise<void> |
- |
Returns
Section titled “Returns”void
References
Section titled “References”redactContext
Section titled “redactContext”Renames and re-exports redact