https://github.com/kessler/node-yalla
A minimalistic logging lib
https://github.com/kessler/node-yalla
Last synced: 22 days ago
JSON representation
A minimalistic logging lib
- Host: GitHub
- URL: https://github.com/kessler/node-yalla
- Owner: kessler
- License: mit
- Created: 2014-09-13T19:11:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-08T10:54:50.000Z (over 8 years ago)
- Last Synced: 2025-04-04T03:31:53.306Z (29 days ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yet Another Logging Library (A) [](http://travis-ci.org/kessler/node-yalla) [](http://github.com/badges/stability-badges)
A minimalistic logging lib
(For the similarly named but completely unrelated .NET library please see [YALLA.NET](http://yalladotnet.github.io/Yalla ))
### simple usage
```javascript
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
```javascript
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
```javascript
var yalla = require('yalla')
var LogLevel = yalla.LogLevelvar log = new Logger(LogLevel.DEBUG)
log.clearOutputs()var consoleLogColoredOutput = {
write: function(args) {
console.log.apply(console, args)
},
prepare: function(level, label, args) {
label = '%c ' + labelvar 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
```javascript
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, SILENTIn all places level constants are interchangable with their lower case string representation