Gathering detailed insights and metrics for @nandn/logger
Gathering detailed insights and metrics for @nandn/logger
A NodeJS module which can be used to log output to console and/or files in style!
npm install @nandn/logger
Typescript
Module System
Node Version
NPM Version
73
Supply Chain
98.9
Quality
75.8
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
1,347
Last Day
1
Last Week
15
Last Month
22
Last Year
298
71 Commits
1 Watching
12 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.5.1
Package Id
@nandn/logger@0.5.1
Unpacked Size
39.59 kB
Size
10.62 kB
File Count
37
NPM Version
9.5.0
Node Version
19.7.0
Publised On
12 Apr 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
1,400%
15
Compared to previous week
Last month
0%
22
Compared to previous month
Last year
-71.6%
298
Compared to previous year
5
Logger
is a Node.js package for logging information with various formatting options. The package provides a simple interface to create a logger with different log levels like debug
, info
, success
, warning
, and error
. Each level has a specific color and symbol to visually differentiate them. The logger can write to files, streams, or an array of files and streams.
You can install Logger
via NPM by running the following command
1npm i @nandn/logger --save-dev
You can install Logger
via NPM by running the following command
1npm i @nandn/logger --save-dev
The Logger
package exports a createLogger
function that you can use to create a new logger instance. The createLogger
function takes two optional arguments:
output
(type: $Loggable | iLoggerOutputs
): This argument specifies where the logs will be written. It can be a stream, file, array of streams or files, or an object that maps log types to streams or files.options
(type: iLoggerOptions
): This argument specifies various formatting options for the logger.1import { createLogger } from '@nandn/logger'; // const { createLogger } = require('@nandn/logger') // for CommonJS system 2 3// Create a logger instance that logs to the console 4const Log = createLogger(); 5 6// Log some information 7Log('Hello, world!'); // outputs "Hello, world!" 8 9// Log some success information 10Log.success('Operation succeeded!'); // outputs "✅ Operation succeeded!" (will be in green color once logged in terminal) 11 12// Log some debug information 13Log.debug('Some debug info'); // outputs "🐞 Some debug info" (will be in purple color once logged in terminal)
1import { createLogger } from '@nandn/logger'; // const { createLogger } = require('@nandn/logger') // for CommonJS system 2import path from 'path'; // const path = require('path') // for CommonJS system 3 4const Log = createLogger( 5 { 6 success: { 7 type: 'FILE', 8 path: path.join(__dirname, './logs/success-logs.log'), 9 }, 10 error: { 11 type: 'FILE', 12 path: path.join(__dirname, './logs/error-logs.log'), 13 options: { 14 // the following options applies to only this perticular output and will take precedence over general options 15 showTime: false, // showTime will be false for this output whereas it will stay true for the rest of the outputs as it is true in general options 16 showSymbol: false, 17 }, 18 }, 19 }, 20 { 21 // general options (applies to all the outputs) 22 showTime: true, 23 } 24); 25 26// Log a success message 27Log.success('This is a success log'); // [Logger] [Wed Apr 12 2023] ✅ This is a success log // This will be logged to `./logs/success-logs.log` 28 29// Log a failure message 30Log.error('This is an error log'); // [Logger] This is an error log // this will be logged to `./logs/error-logs.log` 31 32// Export the logger instance to make it available for the whole project 33export default Log; // module.exports = Log // for CommonJS system
1import { createLogger } from '@nandn/logger'; // const { createLogger } = require('@nandn/logger') // for CommonJS system 2import path from 'path'; // const path = require('path') // for CommonJS system 3 4const Log = createLogger({ 5 // Pass an array to specify multiple outputs 6 success: [ 7 process.stdout, // You can also use 'console' as a short hand to process.stdout 8 { type: 'FILE', path: path.join(__dirname, './logs/success-logs-1.log') }, 9 { type: 'FILE', path: path.join(__dirname, './logs/success-logs-2.log') }, // You can pass as many outputs as you want 10 ], 11 error: [ 12 { type: 'STD_OUT', target: process.stdout, options: { colorize: false } }, // If you want to pass options to an STDOUT, you have to use the STD_OUT type 13 { 14 type: 'FILE', 15 path: path.join(__dirname, './logs/error-logs'), 16 options: { 17 periodic: true, // If periodic is set to true, the logger will create a new file every `period` 18 period: '10 min', // The period can be specified in days, hours, minutes ('1d', '2h', '30m', '4 days', '13 hrs', '2 minutes', '1hr 4min', '1d 2h 30m', etc. are all valid periods) 19 // period: 3600000, // You can also pass the period in milliseconds (in this case you have to pass period as a number instead of a string) 20 }, 21 }, 22 ], 23}); 24 25// Log a success message 26Log.success('This is a success log'); 27/* 28[Logger] ✅ This is a success log // This will be logged to STDOUT in green color 29[Logger] [Wed Apr 12 2023] ✅ This is a success log // This will be logged to `./logs/success-logs-1.log` 30[Logger] [Wed Apr 12 2023] ✅ This is a success log // This will be logged to `./logs/success-logs-2.log` 31*/ 32 33// Log a failure message 34Log.error('This is an error log'); 35/* 36[Logger] ❌ This is an error log // This will be logged to STDOUT without any color (as colorize is set to false for this perticular output) 37[ERROR] [Wed Apr 12 2023] This is an error log // this will be logged to `./logs/error-logs/12-4-2023 23.40.00 - 12-4-2023 23.50.00.log` 38 39Every thing logged in between '12-4-2023 23.40.00' and '12-4-2023 23.50.00' will be logged to the same file 40If you try to log something just after that period, a new file will be created, which will be named as '12-4-2023 23.50.00 - 13-4-2023 00.00.00.log' 41If you don't log anything for let's say 3 hrs, no files will be created in that time period 42*/ 43// Export the logger instance to make it available for the whole project 44export default Log; // module.exports = Log // for CommonJS system
Option | Type | Default | Description |
---|---|---|---|
loggerName | string | 'Logger' | The name of the logger. This is used to prefix the log messages. |
processArgs | boolean | false | Whether to process the arguments passed to the logger. If set to true , the logger will process the arguments passed to it and format them accordingly. |
argsProcessor | function | JSON.stringify | A function that processes the arguments passed to the logger. This function is called only if processArgs is set to true . |
newLine | boolean | true | Whether to add a new line after each log message. |
lineEnding | string | '\n' | The line ending to use. |
showSymbol | boolean | true | Whether to show the log symbol. |
spaceAfterSymbol | boolean | true | Whether to add a space after the log symbol. |
showName | boolean | true | Whether to show the logger name. |
useBracketsForName | boolean | true | Whether to use brackets to enclose the logger name. |
nameFormatter | function | name => name | A function that formats the logger name. |
symbols | object | {} | An object that maps log types to symbols. |
Click here for more details.
This project is licensed under the MIT License - see the LICENSE file for details
No vulnerabilities found.
No security vulnerabilities found.