-
A lightweight, colorful, and feature-rich TypeScript logger with zero dependencies.
-
install
spacefirst.# install space i @je-es/slog// import import { Logger } from '@je-es/slog';
-
-
// Create a logger instance const logger = new Logger('info', false); // Log at different levels logger.debug({ userId: 123 }, 'User lookup'); logger.info({ status: 'ready' }, 'Server initialized'); logger.warn({ memory: '85%' }, 'High memory usage'); logger.error({ code: 'ECONNREFUSED' }, 'Database connection failed'); logger.fatal({ error: 'OutOfMemory' }, 'Critical system error'); // Output (JSON format): // {"timestamp":"2024-12-04T01:35:12.665Z","level":"INFO","message":"Server initialized","status":"ready"}
-
// Enable pretty mode for colorful, readable logs const logger = new Logger('info', true); logger.info({ userId: 123 }, 'User authenticated'); // Output: 01:35:12 β User authenticated userId:123 logger.warn({ disk: '90%' }, 'Low disk space'); // Output: 01:35:12 β Low disk space disk:90% logger.error({ code: 500 }, 'Internal error'); // Output: 01:35:12 β Internal error code:500
-
const logger = new Logger('info', true); // Automatically formats HTTP request logs logger.info({ method: 'GET', path: '/api/users', status: 200, duration: 45 }); // Output: 01:35:12 GET /api/users 200 45ms (colored)
-
const logger = new Logger('info', false); // Create namespaced loggers for different services const apiLogger = logger.child('API'); const dbLogger = logger.child('Database'); apiLogger.info({ endpoint: '/users' }, 'Request received'); // Output: {"timestamp":"...","level":"INFO","message":"[API] Request received","endpoint":"/users"} // Nested child loggers const userService = apiLogger.child('Users'); userService.info({ userId: 123 }, 'User created'); // Output: {"timestamp":"...","level":"INFO","message":"[API:Users] User created","userId":123}
-
// Set minimum log level (debug < info < warn < error < fatal) const logger = new Logger('warn', false); logger.debug({ test: 1 }, 'Debug msg'); // β Won't log logger.info({ test: 2 }, 'Info msg'); // β Won't log logger.warn({ test: 3 }, 'Warning msg'); // β Will log logger.error({ test: 4 }, 'Error msg'); // β Will log logger.fatal({ test: 5 }, 'Fatal msg'); // β Will log
-
const logger = new Logger('info', true); // Route registration logger.info({ method: 'GET', path: '/api/users' }, 'Route added'); // Output: 01:35:12 β GET /api/users logger.info({ method: ['GET', 'POST'], path: '/api/auth' }, 'Route added'); // Output: 01:35:12 β GET|POST /api/auth // Database connection logger.info({ name: 'PostgreSQL' }, 'β Database connected'); // Output: 01:35:12 β Database connected (PostgreSQL) // Server startup logger.info({ url: 'http://localhost:3000' }, 'Server started'); // Output: 01:35:12 β Server started at http://localhost:3000
-
const logger = new Logger('info', false); // You can pass a string directly as the data parameter logger.info('Simple message'); // Output: {"timestamp":"...","level":"INFO","message":"Simple message"} // Works in pretty mode too const prettyLogger = new Logger('info', true); prettyLogger.info('Application started'); // Output: 01:35:12 β Application started
-
-
-
Notifications
You must be signed in to change notification settings - Fork 0
A lightweight, colorful, and feature-rich TypeScript logger with zero dependencies.
License
je-es/slog
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Repository files navigation
About
A lightweight, colorful, and feature-rich TypeScript logger with zero dependencies.

