  
npm install @caravan-logger/logger!NPM Last Update !NPM Last Update !NPM Last Update
A flexible, transport-based logging system for JavaScript/TypeScript applications.
- Multiple transport support (see Transports);
- Log level filtering;
- Context binding through forked loggers;
- Data redaction capabilities;
- TypeScript-first!
``sh
pnpm add @caravan-logger/logger
Usage
`ts
import { Logger } from "@caravan-logger/logger";
import { ConsoleTransport } from "@caravan-logger/transport-console";const logger = new Logger({
level: "INFO",
transports: [
new ConsoleTransport({
options: { pretty: true },
}),
],
});
// Basic logging
logger.info("Hello, world!");
// Logging with metadata
logger.info("User logged in", { userId: "123", ip: "192.168.1.1" });
`Transports
-
ConsoleTransport: a transport that logs to the console with optional pretty printing.
- FileTransport: a transport that logs to a file.
- DatadogTransport: a transport that logs to Datadog.
- BetterStackTransport: a transport that logs to BetterStack.Features
#### Log Levels
-
TRACE: extremely detailed diagnostic information showing every step of execution.
- DEBUG: detailed information useful for development and troubleshooting.
- INFO: general operational messages about program state and execution flow.
- WARN: potentially harmful situations that don't prevent normal operation.
- ERROR: issues preventing specific functionality from working properly.
- FATAL: critical failures that stop core business functions from operating.Each transport can have its own minimum log level, and the logger itself can have a global minimum level.
#### Context Binding
You can create a forked logger with a specific context:
`ts
const userLogger = logger.fork({
context: { userId: "7b2f1c51-511a-4188-a9e1-942a9aab555c" },
});
userLogger.info("Profile updated"); // Will include userId in all logs
`#### Data Redaction
You can configure sensitive data redaction:
`ts
const logger = new Logger({
level: "INFO",
transports: [new ConsoleTransport({ options: { pretty: true } })],
redact: {
paths: ["password", "creditCard.number"],
censor: "[REDACTED]",
},
});
``