loge

Singleton logging with levels

Usage no npm install needed!

<script type="module">
  import loge from 'https://cdn.skypack.dev/loge';
</script>

README

loge

latest version published to npm

My very own Node.js logging library! Crazy that no one else thought of this first!

npm install --save loge

Basic use

The singleton Logger instance defaults to writing to process.stderr.

import {logger, Level} from 'loge'

logger.level = Level.error
logger.warning('You should probably get a doctor to look at that.')
// (nothing)
logger.critical('OMG your face I you what no really just does it hurt?')
// [critical] OMG your face I you what no really just does it hurt?

Alternatively, write to process.stdout:

import {Logger, Level} from 'loge'

const logger = new Logger(process.stdout, Level.info)

Formatting

Loge's calls Node's util.format (but only when the called method's level is greater than or equal to the logger's level), so the following interpolation variables are available:

  • %s - String
  • %d - Number (integer / float)
  • %j - JSON (JSON.stringify() called without replacer or indentation

Use %% for an escaped percent sign

Levels

import {Level} from 'loge'

console.log(Level.notset)
// 0
console.log(Level.debug)
// 10
console.log(Level.info)
// 20
console.log(Level.warning)
// 30
console.log(Level.error)
// 40
console.log(Level.critical)
// 50

License

Copyright © 2014-2015 Christopher Brown. MIT Licensed.