Giter Club home page Giter Club logo

yalm's Introduction

yalm

npm version Dependency Status Build Status XO code style License

A simple javascript logging module for Node.js and the Browser.

Offers 4 logging levels, adds timestamp, severity and colors (even in browser console if possible). Logs via console.log, console.warn (if available) and console.error.

usage

log.debug('a debug message');
log.info('an info message');
log.warn('a warning message');
log.error('an error message');

log.info('array:', [null, 1, 'string', true]);
log.info('buffer:', new Buffer([32, 32]));
log('object:', {"key": "val"});

output of above usage example

Node.js

Node.js sample output

Browser

Browser sample output

options

You can set desired loglevel...

log.setLevel('debug'); // default: 'info'. possible values: 4, 'debug', 3, 'info', 2, 'warn', 1, 'error', 0, 'silent'

... and you can disable printing of timestamps, severity and colors

log.setTimestamp(false);
log.setSeverity(false);
log.setColor(false);

aliases

made for humans...

log('...'); // is an alias of log.info('...');
log.warning('...'); // is an alias of log.warn('...');
log.err('...'); // is an alias of log.error('...');

change styling

if you want another timestamp format overwrite the log.ts function...

log.ts = function () {
    // seconds since epoch
    return '' + Math.floor((new Date()).getTime() / 1000);
};

... if you want to change the severity strings overwrite log.map properties

log.map.debug = 'DEBUG:';
log.map.info = 'INFO:';
log.map.warn = 'WARNING:';
log.map.error = 'ERROR:';

custom log targets

if you want to log in a file or smth you can just overwrite the methods log.stdout, log.stdwrn and log.stderr with your own logging function.

log.stderr = log.stdwrn = log.stdout = function () {
    fs.appendFile('log.txt', Array.prototype.slice.call(arguments).join(' '));
};

license

MIT © Sebastian Raff

yalm's People

Contributors

coldfireice avatar dersimn avatar hobbyquaker avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

coldfireice

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.