Skip to content

kessler/node-yalla

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yet Another Logging Library (A) Build Status stable

A minimalistic logging lib

(For the similarly named but completely unrelated .NET library please see YALLA.NET)

simple usage

	var yalla = require('yalla')

	var log = new yalla.Logger(yalla.LogLevel.SILLY))
	//or
	//var log = new yalla.Logger('silly'))

	if (log.isSilly())
		log.silly('silly %s', util.inspect(something))

	log.debug('debug')
	log.info('info')
	log.warn('warning')
	log.error(new Error())

	// change to warn
	log.setLevel(yalla.LogLevel.WARN)

custom output

	var yalla = require('yalla')
	var util = require('util')

	var log = new yalla.Logger()

	// clear all other outputs (including defaults)
	log.clearOutputs()

	var stream = fs.createWriteStream('my.log')

	log.addOutput(function(args) {
		stream.write(util.format.apply(util, args))
		stream.write('\n')
	})

fancy custom output

example for coloring for chrome console

var yalla = require('yalla')
var LogLevel = yalla.LogLevel

var log = new Logger(LogLevel.DEBUG)
log.clearOutputs()

var consoleLogColoredOutput = {
	write: function(args) {
		console.log.apply(console, args)
	},
	prepare: function(level, label, args) {
		label = '%c ' + label

		var style = 'color: black'

		if (level === LogLevel.DEBUG) {
			style = 'color: green'
		}

		if (level === LogLevel.INFO) {
			style = 'color: blue'
		}

		if (level === LogLevel.WARN) {
			style = 'color: orange'
		}

		if (level === LogLevel.ERROR) {
			style = 'color: red'
		}

		args.splice(1, 0, style)

		return Logger.addLogLevelLabel(level, label, args)
	}
}

log.addOutput(consoleLogColoredOutput)

named logs

	var yalla = require('yalla')

	var log = new yalla.Logger({
		addTimestamp: false, // optional
		level: 'silly', // optional
		name: 'foo'
	}))

	log.debug('debug') // prints [foo] debug

LogLevels

SILLY, DEBUG, INFO, WARN, ERROR, SILENT

In all places level constants are interchangable with their lower case string representation

About

A minimalistic logging lib

Resources

License

Stars

Watchers

Forks

Packages

No packages published