1.7.7 • Published 7 years ago

juta v1.7.7

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
7 years ago

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 for console.log(), but treated at debug level
  • debug(): prints a blue debug message
  • info(): prints a white info message
  • warn(): prints a yellow warning message
  • error(): 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
  • async : whether async logging should be enabled
    • Options: true or false
    • Nodejs default: true
    • Browser default: false
  • asyncFn : which async function to use
    • Options: setTimeout or process.nextTick
    • Nodejs default: process.nextTick
    • Browser default: setTimeout
  • colors : whether the colors should be enabled
    • Options: true or false
    • Nodejs default: true in develpment, false in production
    • Browser default: (not available)
  • showLine : whether to show the line in the log
    • Options: true or false
    • Nodejs default: true in develpment, false in production
    • Browser default: false
  • 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
  • override : whether console should be overridden. If activated, all calls to console.* will actually go to the Juta implementation.
    • Options: true or false
    • Nodejs default: (not available)
    • Browser default: false

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

1.7.7

7 years ago

1.7.6

7 years ago

1.7.5

7 years ago

1.7.4

7 years ago

1.7.3

7 years ago

1.7.2

7 years ago

1.7.1

7 years ago

1.7.0

7 years ago

1.6.5

7 years ago

1.6.4

7 years ago

1.6.3

7 years ago

1.6.2

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago