![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
The nicelogger module will add some fancy options to the regular console.log in node.js
Inspired by the winston logger, this is a very much
reduced version made from scratch.
npm install nicelogger
A config file is required to load information on nicelogger. Here is an example:
{
"logger" : {
"appInfo" : "../package.json",
"date" : true,
"time" : true,
"machineName" : false,
"separatedTimestamp" : false,
"separatedInfo" : false,
"logLevel" : "all",
"months" : [
"Ene","Feb","Mar","Abr","May","Jun",
"Jul","Ago","Sep","Oct","Nov","Dic"
]
}
}
Nicelogger will load the app name and version from the package.json
.
date : [bool]
Will display or hide the date in the log
time : [bool]
Will display or hide the time in the log
machineName : [bool]
Will display or hide the machine name in the log
separatedTimestamp : [bool]
If setted true, will insert a line break after the timestamp info on the log
separatedInfo : [bool]
If setted true, will insert a line break between every element passed to the log
logLevel : [String|Array]
(optional)
Define the lower log leve, by default is 'debug'. If a string is provided, that will be the lower level of loggin. The log order is:
debug > info > warning > error > log > countdown > progress
Also you can provide an array of log types, this types will be the only ones that will be logged.
months : [array]
A set of month names to display. Default: English
First require nice logger and don't forget the config file
config = require('./config.json');
logger = require('nicelogger').config(config.logger, __dirname);
The second parameter is the path to your app config file (needed to get app name, author, version and few stuff to display on the log, this path works alongside the appInfo
property on the config.json
Now you can use all the features that nice logger has:
logger.welcome({extra_info_optional:true});
The welcome message will log a fancy colored info of your node application. You can provide an optional extraInfo object to log something more on the same welcome box.
logger.box({this_one_is_required:true})
Similar to the welcome message, this box message will create a super fancy log inside a box with the parameters provided
logger.debug('This is a debug message');
logger.info('This is an info message');
logger.warning('This is a warning message');
logger.error('This is an error message');
logger.log('This is a regular log message');
Every log flavour outputs some information about the machine, date, time and type of log (all off this are configurable to display).
The log types are colored on white for regular, blue for debug, green for info, yellow for warning and red for error.
There is no limit of params to send to the logs, just like the ol' console.log
Also is you provide an array or an object, the log will output it formated and colored
//Countdown Function
logger.countdown(
'This is a countdown for {timeout} seconds',
5,1000
);
//Single in-line log
logger.progress(['progress is: ',counter]);
The countdown is a single function that will execute untill the intervals are done, and when finished it will fire the callback
logger.countdown(message, number_of_intervals, interval[, callback]);
message : [string]
The string to send to the countdown. You can define a variable {timeout}
that will receive the current timeout counter on the log.
number_of_intervals : [int]
The number of times the countdown will be executed.
interval : [int]
The time that each interval will last in miliseconds.
callback : [function]
(optional)
This function will be called when the number of invertals reach zero.
The progress is a function that will overwrite itself everytime it is called, use it inside your loops to create loading states. When finished, just set done
to true.
logger.progress(items_to_display[, done]);
items_to_display: [array]
This items will be the output of the log. The reason that this are an array and not a single string is because you can send different variables at the same time and all of them will be written in order.
done : [bool]
(optional)
Set this one to true to insert a line break after the log and end the in-line logging.
Use logger.set
to modify configurations. You can change the logLevel, machineName, etc.
logger.set({logLevel:'error')
logger.debug('This is a debug');
//nothing is displayed since debug is lower than the logLevel
logger.set({logLevel:'debug'},{machineName:true})
logger.info('This is an info message')
//17 Ago 22:13:26 ZeroMac.local [info] This is an info message
All collors are displayed using the consolecolors package. And since it mutates the string prototype, you can use all of those colors and styles on your regular logs, or even mix them into the loggers. For more info take a look at ConsoleColors.
Also built in the logger is a titleize function that will set to uppercase every first letter of a string. Use it like this:
"this is a string".titleize
//This Is A String
There is a test file that uses some of the functions in different ways so you can see how those works together. To fire the test just do:
npm test
17.04.04b
YY.MM.DD[rev]
format17.04.04
0.35.07a
0.33.07a
0.33.05a
0.32.07a
0.32.06g
0.32.06f
0.32.06e
FAQs
A colored logger for node.js
We found that nicelogger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.