iog
Save your logs on disk, so simply.
Installation
npm install --save iog
Example
const Iog = require('iog');
const logger = new Iog('my-module-name', {
onLog(body, type) {
console.log(body, type)
}
});
logger.write('my log info');
logger.write({
also: {
you: 'want, for example an object'
}
});Log format
this produces
logger.write('my log info');this
CONTEXT: my-module-name
DATE: 2018-03-03 20:14:12:367
TYPE: log
BODY:
my log info
---------------------------------------------------------------------------------------
this produces
let obj = {
error: "undefine is not defined",
other: {
meta: "a meta"
}
};
logger.write(obj);this
CONTEXT: my-module-name
DATE: 2018-03-03 20:14:12:367
TYPE: log
BODY:
{
"error": "undefine is not defined",
"other": {
"meta": "a meta"
}
}
---------------------------------------------------------------------------------------
API
Iog
Kind: global class
new Iog(contextName, [opts])
Iog instance
| Param | Type | Default | Description |
|---|---|---|---|
| contextName | string | es. your-module-name |
|
| [opts] | object | options |
|
| [opts.path=] | string | log path |
|
| [opts.logExt] | string | ".log" | log file extension |
| [opts.separator] | string | "---" | log separator |
| [opts.console] | boolean | true | show log in console |
| [opts.rotation] | boolean | false | actives rotation log by date |
| [opts.deleteAge] | number | 0 | delete old log in days, works only if |
| [opts.slim] | boolean | false | slim log |
| [opts.onLog] | function | | a callback function fired when a log is written |
iog.pause() ⇒ Iog
Pause log writing
Kind: instance method of Iog
iog.resume() ⇒ Iog
Resume log writing
Kind: instance method of Iog
iog.write(msg, [type], [show])
Write log
Kind: instance method of Iog
| Param | Type | Default | Description |
|---|---|---|---|
| msg | string | object | message log, you can pass also an object with custom params, in this case remember that Error must be get in this way error.message |
|
| [type] | string | "log" | any type that you want like: log, info, error, trace, warn also custom |
| [show] | boolean | true | disable console for single write |
iog.error(msg)
A wrapper of write that set type to "error"
Kind: instance method of Iog
| Param | Type | Description |
|---|---|---|
| msg | string | object | message log, you can pass also an object with custom params, in this case remember that Error must be get in this way error.message |
iog.warn(msg)
A wrapper of write that set type to "warn"
Kind: instance method of Iog
| Param | Type | Description |
|---|---|---|
| msg | string | object | message log, you can pass also an object with custom params, in this case remember that Error must be get in this way error.message |
iog.info(msg)
A wrapper of write that set type to "info"
Kind: instance method of Iog
| Param | Type | Description |
|---|---|---|
| msg | string | object | message log, you can pass also an object with custom params, in this case remember that Error must be get in this way error.message |
iog.trace(msg)
A wrapper of write that set type to "trace"
Kind: instance method of Iog
| Param | Type | Description |
|---|---|---|
| msg | string | object | message log, you can pass also an object with custom params, in this case remember that Error must be get in this way error.message |
License
Iog is open-sourced software licensed under the MIT license