juta v1.7.7
Juta
Another logging package without dependenciesBasic Usage
Juta exposes 4 basic logging functions, that log any arguments passed prefixed with date and colored:
log(): alias forconsole.log(), but treated atdebugleveldebug(): 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 123Browser
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,0012312The 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.DEBUGin development,Juta.INFOin production - Browser default :
Juta.DEBUG
- Options:
async: whether async logging should be enabled- Options:
trueorfalse - Nodejs default:
true - Browser default:
false
- Options:
asyncFn: which async function to use- Options:
setTimeoutorprocess.nextTick - Nodejs default:
process.nextTick - Browser default:
setTimeout
- Options:
colors: whether the colors should be enabled- Options:
trueorfalse - Nodejs default:
truein develpment,falsein production - Browser default: (not available)
- Options:
showLine: whether to show the line in the log- Options:
trueorfalse - Nodejs default:
truein develpment,falsein production - Browser default:
false
- Options:
timestamp: type of timestamp- Options:
Juta.OFFSET(ms since previous log),Juta.TIME,Juta.DATE - Nodejs default:
Juta.TIMEin develpment,Juta.DATEin production - Browser default:
Juta.OFFSET
- Options:
override: whetherconsoleshould be overridden. If activated, all calls toconsole.*will actually go to the Juta implementation.- Options:
trueorfalse - 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,0012312msNote: the instances expose the same functions and settings as the base class but can have independent configuration and namespaces
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago