NodeJs logger

luisf 098ce398c4 fixes před 7 roky
doc 8d6065b21c Added logger levels to configuration před 8 roky
lib 098ce398c4 fixes před 7 roky
test 8d6065b21c Added logger levels to configuration před 8 roky
CHANGELOG.md 098ce398c4 fixes před 7 roky
README.md 8d6065b21c Added logger levels to configuration před 8 roky
index.js 4f39bea8e5 Initial commit před 8 roky
package.json 098ce398c4 fixes před 7 roky

README.md

Simple log system

var log = require('hlogger').createLogger("name");

log.info("test");

Initial relase

Simple pet project that contains ways to create new Writers, Adapters

Logger

The way developer issues logging

	log.info("info log");
	log.error("error log");
	log.warn("warning log");
	log.verb("verbose log");

Adapter

Log filtering, adapters can be created to receive only error, warning logs

Writer

Attached to adapter, writers will be responsible to write the logs either files, console, sql, socket

Right now only two predefined loggers availalbe: file and console

Log formats

Formats for adapters:

  • %m - The actual message
  • %c - logWriter count
  • %l - TAG name [ERROR,WARN,INFO,VERBOSE]
  • %n - Logger name
  • %e - Ellapsed time per writer
  • %E - Ellapsed per Logger
  • %t - Date string
  • %a - Ascii escape char
  • %% - Literal '%'
  • %| - Special case, all chars after %| will be presented on the right

Config format:

Simple:

{
  "writers":{
    "myconsole": {
      "writer":"console"
    }
  },
  "loggers": {
    "main":["ERROR","VERBOSE","INFO","WARN"]
  },
  "adapters" : [
    {
	  "levels": ["INFO","VERBOSE","WARN","ERROR"],
      "writers": ["myconsole"],
      "loggers": {
        "Hello": ["INFO"],
        "main": ["ERROR"]
       }
    }
  ]
}

Create a set of writers, and setup adapters using those writers

{
  "writers" : {
    "filetolog":{
      "writer":"file",
      "opts":{
        "path":"access.log"
      }
    },
    "errorfile": {
      "writer":"file",
        "opts": {
          "path":"error.log"
        }
      },
    "console1": {
      "writer":"console",
      "opts":{
        "format":{
          "ERROR":"-------------- ERR %m -----------------"
        }
      }
    },
    "console": {
      "writer":"console"
    }
  },
  "adapters" : [
    {
      "levels": ["INFO","VERBOSE"],
      "writers": ["filetolog","console"]
    },
    { 
      "levels":["ERROR","WARN"],
      "writers": ["errorfile","console1"]
    }
  ]
}