Comparing version 0.1.1 to 0.2.0
@@ -5,3 +5,3 @@ { | ||
"description": "An advanced logger for nodejs", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
# Logule | ||
Logule is an advanced logging utility for nodejs. It is analogous to `console.log` and can take multiple arguments, | ||
but additionally it prefixes the current time, the log level, and optionally, a caller prefix. | ||
but additionally it prefixes the current time, the log level, and optionally, prefixed namespaces (with optional padding). | ||
@@ -9,3 +9,3 @@ Shortcut methods for the log levels are available as `log.error`, `log.warn`, `log.info` and `log.debug`. | ||
## Usage | ||
Here's with a prefix: | ||
Here's with a single prefixed namespace: | ||
@@ -19,9 +19,21 @@ ````javascript | ||
 | ||
### Prefix Padding | ||
Padding of the prefix level can be done by setting the second parameter in the constructor to the indentation level you want. | ||
### No Namespace | ||
If Logger is instantiated with no constructor arguments, then the output will simply not contain any prefixes and remove one delimiter. | ||
Everything will be aligned automatically. | ||
### Multiple Namespaces | ||
Simply pass in more strings to get more namespaces prefixed. | ||
````javascript | ||
var log = new Logger('prefix', 16); | ||
var log = new Logger('CONNECTION', 'ESTABLISHMENT'); | ||
log.info('Accepted 192.168.0.160'); | ||
```` | ||
### Namespace Padding | ||
Padding of the namespace can be done by calling the pad method on the instance with the indentation level you want. | ||
````javascript | ||
var log = new Logger('BUILD').pad(16); | ||
```` | ||
Now, the actual log messages will all begin 16 characters after the prefix starts. | ||
@@ -32,22 +44,41 @@ If the prefix is longer than the size limit, it will stand out from the crowd. | ||
### No Prefix | ||
If Logger is instantiated with no constructor arguments, then the output will simply not contain any prefixes and remove one delimiter. | ||
Everything will be aligned automatically. | ||
Note that namespace padding with multiple namespaces is almost impossible to get right (all namespaces pad to an equal length). | ||
If you do enforce superstrict rules, however, the `pad` method will set the pad size for each namespace. | ||
## Passing log around | ||
To give submodules full control over what to send to the logger, simply pass down the log variable to them. | ||
If using multiple namespaces, then having to write them all out in every module when changing the last is not optimal. | ||
If, however, you only want a submodule to be able to log debugs for instance, you can make a sanitized logger function for them without access to `.error`, `.warn` and `.info`. | ||
Therefore, it is possible to make a Logger 'subclass' using `sub()`. | ||
````javascript | ||
var debug = function(){ | ||
return log.debug.apply(log, arguments); | ||
}; | ||
var log = new logule('BUILD'); | ||
var sublog = log.sub('COMPILE'); | ||
// pass sublog to the compilation sub-module | ||
// use log in the hierarchy above | ||
```` | ||
If the same namespace is fine for another module to use, simply pass log to it. | ||
### Filtering log | ||
If you only want a submodule to be able to log debugs for instance, you can save typing and force this behaviour by calling `get` on log. | ||
This will return the correctly closure bound log method and pass that down. | ||
````javascript | ||
var debug = log.get('debug'); | ||
debug("this goes to log.debug - no other methods accessible through this var"); | ||
```` | ||
Alternatively, make a copy of the log instance by filtering out the methods you do not want to allow: | ||
````javascript | ||
var sublog = log.remove('debug', 'info'); | ||
sublog.warn('works').info('suppressed').error('works!'); | ||
log.info('works'); | ||
```` | ||
## Zalgo | ||
̺̑ he comes | ||
H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ | ||
````javascript | ||
log.zalgo("no"); | ||
log.zalgo("all is lost"); | ||
```` | ||
@@ -54,0 +85,0 @@ |
Sorry, the diff of this file is not supported yet
27747
9
91