Giter Site home page Giter Site logo

yalog's Introduction

yalog... Yet Another Logger

yalog is a Node.js logging library that can

  • print log messages according to your own functions
  • be customized per module and per logging level
  • have any amount of logging levels
  • print statements in full color (background too!!!)
  • print statements with console qualities such as "italics" or "bold"
  • print messages with module name and current line number so you know from where it was called
  • be configured from file or by a module

Install

npm install yalog

Usage

Add to your code:

var log = require('yalog').with(module);

module is object defined automatically by Node.js. This allows you to copy and paste the line into each file and leverage your filename. The file name matching is done with module.id or the filename with the working directory and trailing '.js' removed. If you don't want automatic module names, replace it with your desired string name.

var log = require('yalog').with("myCustomName");

Arguments are not inspected unless the log level allows for printing of the statement. This avoids unnecessary object serialization calls before submitting your log statements.

log.info(arg1, arg2, arg3);

Simple Example

var log = require('yalog').with(module);
log.test( "Test"  , 0);
log.trace("Trace" , 1);
log.debug("Debug" , 2);
log.info( "Info"  , 3);
log.warn( "Warn"  , 4);
log.error("Error" , 5);
log.info('Array =', [1, 2, 3, 4], '; Object = ', {one: 1, two: 2});

// 2012-02-16T03:32:29.083Z TRACE main:23 - Trace 1
// 2012-02-16T03:32:29.085Z DEBUG main:24 - Debug 2
// 2012-02-16T03:32:29.085Z INFO  main:25 - Info 3
// 2012-02-16T03:32:29.085Z WARN  main:26 - Warn 4
// 2012-02-16T03:32:29.086Z ERROR main:27 - Error 5
// 2012-02-16T03:32:29.086Z INFO  main:28 - Array = [ 1, 2, 3, 4 ] ; Object =  { one: 1, two: 2 }

Advanced Example

Take a look at the examples directory for different examples.

// Load yalog configuration from another location to keep configurations in one spot.
var maxHelper = require('./examples/max_utilization_helper')
var log = maxHelper.with(module);

var answerObj = {is: 42};
answerObj.and = answerObj;

var ctxObj = {email: "[email protected]", circularObj: answerObj, other: "contextInfo", fn: function(){return true;}};
maxHelper.add_context_flag(ctxObj);

log.info( ctxObj, "The answer to life the universe and everything: '", answerObj, "'")
log.info( ctxObj, "Info counter should be at 2. Counter value:")
log.debug(ctxObj, "Debug counter should be at 1. Counter value:")
log.trace(ctxObj, "this should not execute. Level is not included (too low in stack)")
log.info( ctxObj, "Current 'ctxObj' obj: ", ctxObj)

// 2012-02-16T03:29:12.141Z; [email protected]; INFO ; main:12; -; The answer to life the universe and everything: ' | { is: 42, and: [Circular] } | '; 1
// 2012-02-16T03:29:12.145Z; [email protected]; INFO ; main:13; -; Info counter should be at 2. Counter value:; 2
// 2012-02-16T03:29:12.145Z; [email protected]; DEBUG; main:14; -; Debug counter should be at 1. Counter value:; 1
// 2012-02-16T03:29:12.145Z; [email protected]; INFO ; main:16; -; Current 'ctxObj' obj:  | { email: '[email protected]', circularObj: { is: 42, and: [Circular] }, other: 'contextInfo', fn: [Function], _myContextFlag: true }; 3

Released under MIT License. Enjoy and Fork!

yalog's People

Contributors

schloerke avatar

Stargazers

ken avatar

Watchers

ken avatar

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.