3.1.0 • Published 8 years ago

@larsbrix/logger v3.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

logger

a simple logger we use for r6db.com

Usage

init

Log(config, logConfig)

const Log = require("ggs-logger");
let log = new Log(); // creates a log with default settings

config is an object with the following properties (all optional):

  • threshold: number the minimum level for entries to be printed
  • onLog: function callback which gets called on every log
  • cfg: object override the default levels (trace, debug, info, warn and error)
let levels = {
    10: {						    // level used
        label: "MY_LEVEL",			// used for printing
        style: "color: #eee8624"	// styles applied in the console
    },
    20: {
        label: "CRITICAL",
        style: ""
    }
}

you can use syslog levels like this:

const log = new Log({ levels: Log.levels.syslog });

logConfig is an object wich will be assigned to each log entry:

let log = new Log({}, { jimmies: "rustled"});
log.trace("test"); // => logs {msg: "test", jimmies: "rustled"}

setting time, msg or level will do nothing and get overwritten

methods

assuming that let log = new Log():

misc

methods that are not directly logging

log.child(name)

creates a new sub-log

	let log = new Log();
	log.trace("test") // => logs {msg: "test" ...}
	let child = log.child("child log");
	child.trace("test 2") // => logs {msg: "test", component: "child log" ...}

log.setLevel(level)

override the config threshold

log.entries()

returns all logged entries

log.empty()

clears all entries

log methods

these are teh default methods to log

log.trace(msg,...data)

logs with the lowest level (10);

log.debug(msg, ...data);

logs with level 20

log.info(msg, ...data);

logs with level 30

log.warn(msg, ...data);

logs with level 40

log.error(msg, ...data)

logs with level 50

3.1.0

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.1

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago