Permalink
Browse files

express-winston no longer required for winston; fix default levels; a…

…dd examples;
  • Loading branch information...
1 parent f61c2ec commit a2df9c85eabea426decf9ef9c6a4bed855df28a7 @vjpr committed Aug 19, 2012
Showing with 38 additions and 2 deletions.
  1. +4 −0 README.md
  2. +21 −0 examples/example.coffee
  3. BIN examples/example.png
  4. +13 −2 src/onelog.coffee
View
@@ -34,6 +34,10 @@ Add logging statements like this:
logger = require('onelog).get('Foo.Bar')
logger.debug 'FooBar!'
+For more examples run `npm install && coffee examples/example.coffee`
+
+![examples](https://github.com/vjpr/onelog/tree/master/examples/examples.png)
+
## Configuration
I put all my library dependent configuration in a function so I can easily toggle between libraries.
View
@@ -0,0 +1,21 @@
+#! /usr/local/bin/coffee
+
+onelog = require 'onelog'
+
+onelog.use onelog.Winston
+logger = onelog.get('Foo')
+logger.info 'Hello, World!'
+
+onelog.use onelog.Logule
+logger = onelog.get('Foo')
+logger.info 'Hello, World!'
+
+onelog.use onelog.Tracer
+logger = onelog.get('Foo')
+logger.info 'Hello, World!'
+
+log4js = require 'log4js'
+onelog.use onelog.Log4js
+logger = onelog.get('Foo')
+logger.info 'Hello, World!'
+
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -28,6 +28,9 @@ exports.use = (clazz, opts) ->
_defaultLogger = _library.get()
if opts?.methods?
_.extend config.methods, opts.methods
+ for method in config.methods
+ do (method) =>
+ exports[method] = (a...) -> _defaultLogger[method] a...
# Create or get a logger instance
exports.get = (category) -> _library.get category
@@ -45,7 +48,6 @@ class Logger
constructor: (@logger) ->
for method in config.methods
do (method) =>
- exports[method] = (a...) -> _defaultLogger[method] a...
Logger::[method] = (a...) ->
if @logger[method]?
@logger[method] a...
@@ -62,6 +64,15 @@ class Library
# Default level when an unsupported level is encountered
middleware: (opts) ->
(req, res, next) -> next()
+ # If library doesn't support a level, this default level is used
+ defaultLevel: ->
+ return 'info'
+ if @.log?
+ return 'log'
+ else if @.info?
+ return 'info'
+ else
+ throw new Error 'Could not find a default level to fallback to'
# Provided library adapters
# ------------------------------------------------------------------------------
@@ -107,7 +118,6 @@ class Winston extends Library
constructor: ->
@winston = require 'winston'
- @expressWinston = require 'express-winston'
get: (category) ->
logger = null
@@ -121,6 +131,7 @@ class Winston extends Library
logger
middleware: (opts) ->
+ @expressWinston = require 'express-winston'
if opts?.winston.type is 'error'
return @expressWinston.errorLogger
transports: [

0 comments on commit a2df9c8

Please sign in to comment.