Giter Site home page Giter Site logo

knoblr's Introduction

Knoblr

NodeJs Dependencies codecov Build Status Codacy Badge

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 = require('knoblr');

Then you can use like this:

const log = require('knoblr');

log.warn('This is a warn text');
log.error('This is an error text');
log.info('This is an info text');

This will be the output:

Log 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 = require('knoblr');

var warnString = log.warn('This is a warn text', true); //this will return a string instead
var errorString = log.error('This is an error text', true); //this will return a string instead
var infoString = log.info('This is an info text', true); //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 = require('knoblr');

log.setTimeFormat("Your format Here");

log.warn('This is a warn text with your timestamp');
log.error('This is an error text with your timestamp');
log.info('This is an info text with your timestamp');

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 = require('knoblr');

log.displayTimestamp = false;

log.warn('This is a warn text without the timestamp');
log.error('This is an error text without the timestamp');
log.info('This is an info text without the timestamp');

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 = require('knoblr');

log.displayLogType = false;

log.warn('This is a warn text without the log type');
log.error('This is an error text without the log type');
log.info('This is an info text without the log type');

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 = require("../dist/log.js");
log.setLogColor('info', log.colors.green);
log.setLogColor('warn', log.colors.cyan);
log.setLogColor('error', log.colors.bgYellow);

log.warn('This will be cyan');
log.error('This will have an awesome yellow bg');
log.info('This will be green');

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:

Test output

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.

knoblr's People

Contributors

dependabot[bot] avatar khaosdoctor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

knoblr's Issues

Support spread args

Support for spread args such as: knoblr.info(1,2,3,4,5) to log as [date] => {type} 1 2 3 4 5

Remove duplicated code

There's some code duplication there which is lowering the code climate grade, remove it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.