createLogger
Problem
Debugging an LLM agent without logs is guesswork. But adding raw console.log statements everywhere creates noise in production and is hard to control. You end up either seeing too much or too little — and toggling it requires editing multiple files.
Solution
createLogger creates a structured logger you configure once. You control what gets logged (steps, tools, errors), what level is visible, and whether logging is on at all. In production, set enabled: false — nothing leaks. In development, turn on steps and tools to see exactly what the agent is doing.
Feature & Use-Case
Use createLogger when:
- You want step-by-step visibility into your agent loop during development
- You need to log tool calls with their input for debugging
- You want production-safe logging — turn it off with one flag, no code changes
- You are building a Node.js LangChain agent and need structured, level-gated output
Import
import { createLogger } from "llm-layer-engine";Function Signature
function createLogger(config?: LoggerConfig): {
step(step: number, message: string): void;
tool(name: string, input: unknown): void;
warn(message: string): void;
error(err: unknown): void;
info(message: string): void;
}LoggerConfig Options
type LoggerConfig = {
enabled?: boolean; // Master switch. Default: false
level?: LogLevel; // "debug" | "info" | "warn" | "error". Default: "info"
steps?: boolean; // Log each agent step. Default: false
tools?: boolean; // Log tool calls with input. Default: false
errors?: boolean; // Log errors. Default: true
};Log Level Order
debug → info → warn → error
Setting level: "warn" means only warn and error messages are shown. Setting level: "debug" shows everything.
Example — Development Setup
import { createLogger } from "llm-layer-engine";
const logger = createLogger({
enabled: true,
level: "debug",
steps: true,
tools: true,
errors: true,
});
logger.step(1, "Starting agent run");
// → [STEP 1] Starting agent run
logger.tool("get_weather", { city: "Karachi" });
// → [TOOL] get_weather { city: "Karachi" }
logger.info("Loop completed");
// → [INFO] Loop completed
logger.warn("maxSteps reached without final answer");
// → [WARN] maxSteps reached without final answer
logger.error(new Error("Provider timeout"));
// → [ERROR] Error: Provider timeoutExample — Production Setup (Silent)
const logger = createLogger({
enabled: false,
});
logger.step(1, "This will not print");
logger.tool("anything", {});
// → (no output)Pass the same logger object everywhere. When enabled is false, every method is a no-op.
Example — Integrate Into a Custom Loop
import { createLogger, executeStep } from "llm-layer-engine";
const logger = createLogger({ enabled: true, level: "debug", steps: true, tools: true });
let step = 0;
while (step < maxSteps) {
logger.step(step + 1, "Executing agent step");
const result = await executeStep({ provider, config, tools, conversation });
if (result.errors > 0) {
logger.error("Step encountered an error");
}
step++;
if (result.isFinished) break;
}Conclusion
createLogger is a zero-dependency, configuration-first logger built for LLM agents. Create one instance per agent or service, pass the config from an environment variable, and you have full control over what gets logged without touching your agent logic. Use enabled: process.env.NODE_ENV !== "production" to toggle automatically.