Zero-dependency TypeScript logger with structured logging, multiple transports, and beautiful output
npm install @lytics/keroZero-dependency TypeScript logger with structured logging, multiple transports, and beautiful output.
Inspired by Pino, built for modern TypeScript applications.
- ๐ Zero runtime dependencies - Only uses Node.js built-ins
- ๐ Structured logging - First-class support for objects and metadata
- ๐จ Beautiful output - Pretty console output for development, JSON for production
- โก Fast & lightweight - Minimal overhead, maximum performance
- ๐ง TypeScript-first - Full type safety out of the box
- ๐ฏ Child loggers - Inherit configuration and add contextual data
- โฑ๏ธ Built-in timers - Measure operation duration easily
- ๐ Icons support - Visual scanning with Unicode or emoji icons
- ๐ฆ ESM & CJS - Works with both module systems
- ๐ญ Multiple presets - Development, production, and test configurations
``bash`
pnpm add @lytics/kero
`typescript
import { kero } from '@lytics/kero';
// Basic logging
kero.info('Server started');
kero.success('Deployment complete');
kero.debug({ port: 3000 }, 'Listening');
kero.error(new Error('Failed'), 'Request failed');
`
`typescript
import { createLogger } from '@lytics/kero';
const logger = createLogger({
level: 'debug', // Minimum level: trace, debug, info, warn, error, fatal
format: 'pretty', // Output format: 'pretty' or 'json'
});
`
`typescript
import { createLogger } from '@lytics/kero';
// Development: pretty output, debug level
const devLogger = createLogger({ preset: 'development' });
// Production: JSON output, info level
const prodLogger = createLogger({ preset: 'production' });
// Test: JSON output, warn level (minimal noise)
const testLogger = createLogger({ preset: 'test' });
`
Child loggers inherit parent configuration and add context:
`typescript
const logger = createLogger({ level: 'info' });
const reqLogger = logger.child({ requestId: 'abc-123' });
reqLogger.info('Processing'); // Includes requestId in output
`
Pass an object as the first argument for structured data:
`typescript`
logger.info({ userId: 42, action: 'login' }, 'User authenticated');
// JSON: {"level":30,"time":1732505525000,"userId":42,"action":"login","msg":"User authenticated"}
// Pretty: [14:32:05] INFO User authenticated {"userId":42,"action":"login"}
Pass an Error as the first argument:
`typescript`
try {
riskyOperation();
} catch (err) {
logger.error(err, 'Operation failed');
}
Measure operation duration:
`typescript`
const done = logger.startTimer('database-query');
await db.query(sql);
done(); // Logs: "database-query completed (42ms)"
From lowest to highest priority:
| Level | Value | Description |
|---------|-------|--------------------------|
| trace | 10 | Detailed tracing |debug
| | 20 | Debug information |info
| | 30 | Normal operations |warn
| | 40 | Warning conditions |error
| | 50 | Error conditions |fatal
| | 60 | System is unusable |
``
[14:32:05] INFO Server started
[14:32:05] DEBUG Listening {"port":3000}
[14:32:06] INFO (abc-123) Processing
Enable icons for visual scanning:
`typescript
import { createLogger, PrettyFormatter } from '@lytics/kero';
// Unicode icons (default when icons=true) - works everywhere
const logger = createLogger({
formatter: new PrettyFormatter({ icons: true }),
});
// Or explicitly: icons: 'unicode' or icons: 'emoji'
`
Unicode icons (terminal-safe):
``
[14:32:05] ยป TRACE Detailed info
[14:32:05] โ DEBUG Listening {"port":3000}
[14:32:05] โ INFO Server started
[14:32:05] โ INFO Deployment complete (success)
[14:32:06] โฒ WARN Memory usage high
[14:32:07] โ ERROR Request failed
| Level | Unicode | Emoji |
|-----------|---------|-------|
| trace | ยป | ๐ |debug
| | โ | ๐ |info
| | โ | โน๏ธ |success
| | โ | โ
|warn
| | โฒ | โ ๏ธ |error
| | โ | โ |fatal
| | โ | ๐ |
`json`
{"level":30,"time":1732505525000,"msg":"Server started"}
{"level":20,"time":1732505525001,"port":3000,"msg":"Listening"}
{"level":30,"time":1732505526000,"requestId":"abc-123","msg":"Processing"}
Implement the Formatter interface:
`typescript
import { createLogger, Formatter, LogEntry } from '@lytics/kero';
const myFormatter: Formatter = {
format(entry: LogEntry): string {
return [${entry.level}] ${entry.msg};
}
};
const logger = createLogger({ formatter: myFormatter });
`
Implement the Transport interface:
`typescript
import { createLogger, Transport, LogEntry } from '@lytics/kero';
const myTransport: Transport = {
write(entry: LogEntry, formatted: string): void {
// Send to your logging service
fetch('/logs', { method: 'POST', body: formatted });
}
};
const logger = createLogger({ transports: [myTransport] });
`
Creates a new logger instance.
Options:
- level: Minimum log level (default: 'info')format
- : Output format 'pretty' | 'json' (default: 'pretty')formatter
- : Custom formatter instancetransports
- : Array of transports (default: [ConsoleTransport])context
- : Default context for all log entriespreset
- : Preset name 'development' | 'production' | 'test'
Default logger instance with development preset.
- trace(msg) / trace(obj, msg) - Log at trace leveldebug(msg)
- / debug(obj, msg) - Log at debug levelinfo(msg)
- / info(obj, msg) - Log at info levelsuccess(msg)
- / success(obj, msg) - Log success at info level (with โ icon)warn(msg)
- / warn(obj, msg) - Log at warn levelerror(msg)
- / error(err, msg) / error(obj, msg) - Log at error levelfatal(msg)
- / fatal(err, msg) / fatal(obj, msg) - Log at fatal levelchild(context)
- - Create child logger with added contextstartTimer(label)
- - Start a timer, returns function to stop and logisLevelEnabled(level)
- - Check if level would be loggedlevel
- - Get current log level
This package has zero runtime dependencies. It uses only Node.js built-ins:
- process.stdout / process.stderr for outputprocess.env` for color detection
-
Kero (ใฑใญใฑใญ) is the Japanese onomatopoeia for a frog's croak - the sound frogs make. Just like how a frog's call cuts through the noise to be heard clearly, kero helps your logs stand out with beautiful, structured output that's easy to read and understand.
| Feature | Kero | Pino | Winston | Bunyan |
|---------|------|------|---------|--------|
| Zero dependencies | โ
| โ | โ | โ |
| TypeScript-first | โ
| โ | โ | โ |
| Pretty console output | โ
| โ ๏ธ (separate package) | โ
| โ ๏ธ (via CLI) |
| Structured logging | โ
| โ
| โ
| โ
|
| Child loggers | โ
| โ
| โ
| โ
|
| Built-in timers | โ
| โ | โ
| โ |
| Package size | ~15KB | ~100KB | ~300KB | ~200KB |
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT ยฉ Lytics