sbis3-cloud-logger
v0.3.3
Published
Simple logger for SBIS3 Cloud
Downloads
3
Readme
SBIS3 Cloud Logger
Install
npm install sbis3-cloud-logger --save
Use
Module exports a singleton object (only one instance per working process).
var logger = require('sbis3-cloud-logger');
Before sending logs, it must be configured using init()
method.
Pass options object to init()
to set logger options.
// If both url and cloud is set - priority to cloud
// You MUST specify one of them
logger.init({
url: 'https://some.host.tld/path/to/backend', // Full logging backend URL.
cloud: 'online.sbis.ru', // Cloud hostname.
logThreshold: 500, // how many log records to keep before sending. Default: 100
queueCheckTime: 5000, // how often to check log buffer. Default: 1000
appName: 'My Awesome Service', // Application name (appears in log). Default: 'Node'
sendTimeout: 1000, // If sending is taking this more time, abort it
appPort: 5555 // Application port (appears in log). Default: 0
});
After first call to init()
is made, all further call will be completely ignored.
If cloud
parameter is not set while doing init()
, exception is thrown.
When done with initialization, use log()
method.
logger.log('Bam! Exception!');
logger.log('Loading resources...', 'INFO');
logger.log('Watch out! Memory is almost full!', 'WARNING');
Instead of passing a text message as a first parameter, one can pass object with fields:
- msg
- method
- extip
- intip
logger.log({
msg: 'Log message',
method: 'Object.Method'
});
If init()
is not done, all calls to log()
is useless and completely ignored.
If you need to forcibly flush logs, use flush()
method (since 0.2.0 it flushes logs immediately,
not on a next timer tick as of 0.1.0).
To terminate logger (this will prevent further logs transmission) use end()
method.
Both methods accepts optional callback which will fire when logs are flushed or error occurs during sending logs.
Hacks
If DISABLE_CLOUD_LOG
environment variable is set, logger is doing nothing. All calls to log()
are ignored.