-
-
Unified logging interface across your entire stackβserver, client, and beyond. Standardizes log formatting and ensures consistent structured data handling throughout your application.
-
When you use @minejs/server or @cruxjs/app
-
-
install
hmmfirst.# in your terminal hmm i @minejs/logger// in your ts files import { Logger } from `@minejs/logger`;
-
// 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
-
-
-
-
Creates a logger instance with specified configuration.
const logger = new Logger('info', true, 'MyApp'); // level: 'debug' | 'info' | 'warn' | 'error' (default: 'info') // pretty: boolean - Enable colored output (default: false) // prefix: string - Add prefix to all messages (default: '')
-
Log at debug level (lowest priority).
logger.debug({ userId: 123 }, 'User lookup'); // Only shows if level is set to 'debug'
-
Log at info level for general information messages.
logger.info({ status: 'ready' }, 'Server initialized');
-
Log at warning level for potential issues.
logger.warn({ memory: '85%' }, 'High memory usage');
-
Log at error level for application errors.
logger.error({ code: 'ECONNREFUSED' }, 'Database connection failed');
-
Log at fatal level (highest priority) for critical errors.
logger.fatal({ error: 'OutOfMemory' }, 'Critical system error');
-
Create a child logger with a namespaced prefix.
const apiLogger = logger.child('API'); const userLogger = apiLogger.child('Users'); // Creates nested prefixes: [API:Users]
-
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Unified logging across your stack with JSON and pretty mode support.
License
minejs-org/logger
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Β | Β | |||
Repository files navigation
About
Unified logging across your stack with JSON and pretty mode support.

