@micl/server-log
v0.0.2
Published
A simple and customizable server-side logger for Node.js applications, supporting multiple logging levels and module-specific logs.
Readme
@micl/server-log
A simple and customizable server-side logger for Node.js applications, supporting multiple logging levels and module-specific logs.
Installation
npm install @micl/server-lognpm Page
Usage
Importing the Logger
const { serverLogger, initLogger } = require('@micl/server-log');Initializing the Logger
By default, logs are stored in the ./logs directory. If the specified directory does not exist, the script will create it automatically. You can also specify a custom directory and module-specific loggers:
initLogger(['auth', 'database'], './server-logs');Logging Messages
General Logs
serverLogger.info('Server started');
serverLogger.warn('Memory usage is high');
serverLogger.error('Failed to connect to database');Module-Specific Logs
If you initialized the logger with modules (e.g., auth and database), you can log messages for these modules:
serverLogger.auth.info('User login successful');
serverLogger.database.error('Database connection lost');Log Output Format
Each log entry is prefixed with a timestamp and log level:
[INFO][HH:MM:SS] Server started
[WARN][HH:MM:SS] Memory usage is high
[ERROR][HH:MM:SS] Failed to connect to databaseContributing
You can contribute to this module online via CodeSandBox, or locally:
- Clone the repository.
- Install dependencies with
yarn installornpm install. - Start the development server using
yarn devornpm run dev.
License
This project is licensed under the MIT License.
Copyright (c) alexgogoing [email protected]
