Knoblr
Knoblr is a simple logging library to help node developers.
What is
It basically adds a funcionality of displaying three types of logs:
- Warns
- Errors
- Info
Very simple. And it comes along with a timestamp, and color codes!
Installing
Just perform a npm install --save knoblr
Using
In your file require the logger:
const log = ;
Then you can use like this:
const log = ; log;log;log;
This will be the output:
API
There's also an API to help developers get their error messages straight and format them as they please. All you need to do is set a second parameter to true
:
const log = ; var warnString = log; //this will return a string insteadvar errorString = log; //this will return a string insteadvar infoString = log; //this will return a string instead
Customizing usage
There are options to customize the output of the log, such as:
- Datetime formats
- Whether or not to display the timestamp
- Displaying log type
- Logging colors
Datetime formats
Knoblr uses Moment.js to issue times and formats, so all the Moment's formats will be compatible with Knoblr.
Refer to this url to know more about formats.
In order to set the time formats you can do:
const log = ; log; log;log;log;
The default time format is YYYY-MM-DD HH:mm:ss
(In other words its <4-digit year>/<2-digit month>/<2-digit-day> <24h hours>:<2-digit minutes>:<2-digit seconds>
).
Displaying the timestamp
You have the choice not to display the timestamp along with the log, just set:
const log = ; logdisplayTimestamp = false; log;log;log;
Displaying log type
Same as before, you can choose not to show {WARN}
, {INFO}
and {ERROR}
texts during logs, for that to happen all you have to do is:
const log = ; logdisplayLogType = false; log;log;log;
Log colors
Knoblr uses Chalk as colorizer, so you can set an instance of chalk using Knoblr return implementation object.
Knoblr exposes chalk as an instance so the you don't need to require it:
const log = ;log;log;log; log;log;log;
Reset
If you want to switch back to the original values just perform a log.reset()
.
Check the basetest file to get a glimpse of all commands.
This will be the output of the tests:
License
MIT @ Lucas Santos
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.