iog

1.6.0 • Public • Published

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

ParamTypeDefaultDescription
contextNamestring

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]booleantrue

show log in console

[opts.rotation]booleanfalse

actives rotation log by date

[opts.deleteAge]number0

delete old log in days, works only if rotation is true

[opts.slim]booleanfalse

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

ParamTypeDefaultDescription
msgstring | 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]booleantrue

disable console for single write

iog.error(msg)

A wrapper of write that set type to "error"

Kind: instance method of Iog

ParamTypeDescription
msgstring | 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

ParamTypeDescription
msgstring | 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

ParamTypeDescription
msgstring | 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

ParamTypeDescription
msgstring | 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

Author

Fabio Ricali

Package Sidebar

Install

npm i iog

Weekly Downloads

0

Version

1.6.0

License

MIT

Unpacked Size

17.3 kB

Total Files

7

Last publish

Collaborators

  • fabioricali