juta
v1.7.7
Published
Another logging package with no dependencies
Downloads
6
Readme
Juta
Another logging package without dependencies
Basic Usage
Juta exposes 4 basic logging functions, that log any arguments passed prefixed with date and colored:
log()
: alias forconsole.log()
, but treated atdebug
leveldebug()
: prints a blue debug messageinfo()
: prints a white info messagewarn()
: prints a yellow warning messageerror()
: prints a red error message
Nodejs
var Juta = require('juta');
Juta.debug('debug message', { key : 'value' });
// prints: [03/16/17 15:48:02.0987] debug message { key : 'value' }
// (will not be printed if NODE_ENV is 'production')
Juta.info('this is an info message', 123, 'and more');
// prints: [03/16/17 15:48:02.0987] this is an info message 123 and more
Juta.warn('wow, warning message', 'another string');
// prints: [03/16/17 15:48:02.0987] wow, warning message another string
Juta.error('this is an error message');
// prints: [03/16/17 15:48:02.0987] this is an error message
Juta.error(new Error('here is the error'), 123);
// prints: [03/16/17 15:48:02.0987] ERROR: here is the error 123
Browser
TODO
Async logging
By default, Juta logs asynchronously through process.nextTick()
. To disable this behaviour, use config or a configurable instance (see later).
Time
Juta offers a simple timer utility:
var timer = Juta.tic('my label');
var logTimerResult = true;
var end = timer.toc(logTimerResult)
// prints: [03/16/17 15:48:02.0987] my label timer: 0,0012312ms
Juta.debug(end+1)
// prints [03/16/17 15:48:02.0988] 1,0012312
The printed message is by default a debug message.
Global config
By calling Juta.set(config, value)
it is possible to configure the global Juta instance. Here the possible configuration:
minLevel
: minimum logging level (Juta.DEBUG
,Juta.WARNING
, etc)- Options:
Juta.DEBUG
,Juta.INFO
,Juta.WARNING
,Juta.ERROR
- Nodejs default :
Juta.DEBUG
in development,Juta.INFO
in production - Browser default :
Juta.DEBUG
- Options:
async
: whether async logging should be enabled- Options:
true
orfalse
- Nodejs default:
true
- Browser default:
false
- Options:
asyncFn
: which async function to use- Options:
setTimeout
orprocess.nextTick
- Nodejs default:
process.nextTick
- Browser default:
setTimeout
- Options:
colors
: whether the colors should be enabled- Options:
true
orfalse
- Nodejs default:
true
in develpment,false
in production - Browser default: (not available)
- Options:
showLine
: whether to show the line in the log- Options:
true
orfalse
- Nodejs default:
true
in develpment,false
in production - Browser default:
false
- Options:
timestamp
: type of timestamp- Options:
Juta.OFFSET
(ms since previous log),Juta.TIME
,Juta.DATE
- Nodejs default:
Juta.TIME
in develpment,Juta.DATE
in production - Browser default:
Juta.OFFSET
- Options:
override
: whetherconsole
should be overridden. If activated, all calls toconsole.*
will actually go to the Juta implementation.- Options:
true
orfalse
- Nodejs default: (not available)
- Browser default:
false
- Options:
Configurable instances
It is possible to instanciate and object of type Juta that takes parameters in the constructor:
var Juta = require('juta');
var log = new Juta({namespace : 'ThisScript',
async : true,
minLevel : Juta.WARNING })
log.debug('debug message', { key : 'value' });
// doesn't print anything, minLevel is warning
log.info('this is an info message', 123, 'and more');
// doesn't print anything, minLevel is warning
log.warn('warning', 'message');
// prints: [03/16/17 15:48:02.0987] [ThisScript] warning message
log.error('error message');
// prints: [03/16/17 15:48:02.0987] [ThisScript] error message
var timer = log.tic('something');
time.toc(true);
// prints: [03/16/17 15:48:02.0987] [ThisScript] something timer: 0,0012312ms
Note: the instances expose the same functions and settings as the base class but can have independent configuration and namespaces