Gathering detailed insights and metrics for turbo-logger
Gathering detailed insights and metrics for turbo-logger
Gathering detailed insights and metrics for turbo-logger
Gathering detailed insights and metrics for turbo-logger
npm install turbo-logger
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
6 Stars
99 Commits
1 Forks
2 Watching
3 Branches
3 Contributors
Updated on 08 Sept 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
200%
3
Compared to previous day
Last week
220%
16
Compared to previous week
Last month
-48.5%
35
Compared to previous month
Last year
-46.5%
1,250
Compared to previous year
TurboLogger is a versatile logging library for Node.js applications that supports logging to the console, file, and Slack channel. It provides configurable logging levels (error, info, warn), single and hybrid logging capabilities, and customizable logging contexts.
Install TurboLogger using npm:
1 npm i --save turbo-logger
1 import turboLogger from 'turbo-logger'; 2 3 const config = { 4 "slack": { 5 webhook_url: `${process.env.WEBHOOK_URL}`, 6 channel: 'sample-channel', 7 } 8 } 9 10 const env = { 11 prod: ['console', 'slack'], 12 dev: ['file', 'console'], 13 myCustomConfig: ['console'] 14 } 15 16 const logger = turboLogger.createStream(config, env.prod);
Once the logger is initialized, you can use it to log messages:
1 logger.log('hello world'); // logs the message to the console and Slack with an "info" context 2 logger.warn('hello world'); // logs the message to the console with a "warn" context 3 logger.error('hello world'); // logs the message to a file and the console with an "error" context
You need to initialize the logger with the slack config if you plan on logging to Slack. If not, you can use like so.
1 import turboLogger from 'turbo-logger'; 2 const logger = turboLogger.createStream(); // env will default to logging to console. 3
To log only to Slack, set the environment parameter to "slack" and provide the required Slack configuration. Please note that in order to use this feature, you need to create a Slack app and obtain the necessary credentials.
Here's how to set up the Single Logger for Slack:
Create a Slack app following the instructions in the Slack App Creation Guide..
Obtain the webhook_url and channel for your Slack app. The webhook_url is a unique URL that allows your application to send messages to a specific Slack channel. This is gotten from the "incoming webhook" settings for the slack app you created. Enable it and set the channel you want the message to be sent to. Slack creates a separate webhook url for eah channel. ![](Webhook Screen)
Configure the config object with the webhook_url and channel values:
1 const config = { 2 "slack": { 3 webhook_url: `${process.env.WEBHOOK_URL}`, 4 channel: 'sample-channel', 5 } 6 } 7 8 const env = ['slack'] 9 const logger = turboLogger.createStream(config, env); 10 logger.log('hello world'); // sends the message to the specified Slack channel
Ensure that you replace ${process.env.SECRET} in the webhook_url with the actual secret value obtained from your Slack app.
Note: If the config object does not have the required webhook_url and channel parameters, TurboLogger will throw an error.
The hybrid logger combines multiple log levels. It could be a combination of all three or any two levels. To use this, we set the environment configuration to include all three or any two log levels:
1 const env = ['console', 'slack', 'file'] 2 const logger = turboLogger.createStream(config, env); 3 logger.log('hello world'); // sends the message to all contexts (console, Slack, and file)
TurboLogger allows you to log comma-separated messages. For example:
1 logger.log('My config object: ', config);
The console prints:
You can log as many comma-separated messages as you want.
You can log to several Slack channels. The logger streams are configured separately as every channel
1 import turboLogger from 'turbo-logger'; 2 const env = ['slack']; 3 4 // Error channel set up 5 const errorChannelName = "error-logs"; 6 const errorChannelConfig = { 7 "slack": { 8 webhook_url: `${process.env.SLACK_ERROR_CHANNEL_WEBHOOK_URL}`, 9 channel: errorChannelName, 10 } 11 }; 12 13 // Success channel set up 14 const successChannelName = "success-logs"; 15 const successChannelConfig = { 16 "slack": { 17 webhook_url: `${process.env.SLACK_SUCCESS_CHANNEL_WEBHOOK_URL}`, 18 channel: successChannelName, 19 } 20 }; 21 22 // Instantiate logger 23 const slackErrorLogger = turboLogger.createStream(errorChannelConfig, env); 24 const slackSuccessLogger = turboLogger.createStream(successChannelConfig, env); 25 26 // Usage 27 slackErrorLogger.error("Internal server error") // This sends a message with an error context to the channel named "error-logs" 28 slackSuccessLogger.log("Request successful") // This sends a message with an info context to the channel named "success-logs"
TurboLogger is licensed under the MIT License.
TurboLogger was created by Gideon Odiase.
Buy me a coffee here.
No vulnerabilities found.
No security vulnerabilities found.