Skip to content

Commit

Permalink
module now requires passing config as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nisaacson committed Mar 25, 2013
1 parent 589cafe commit ffd057f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 54 deletions.
107 changes: 54 additions & 53 deletions index.js
@@ -1,62 +1,63 @@
var config = require('nconf')
var Loggly = require('winston-loggly').Loggly
var winston = require('winston');
var loggly = config.get('loggly')
// prepare some custom log levels
var customLevels = {
levels: {
debug: 0,
info: 1,
warning: 2,
error: 3
},
colors: {
debug: 'blue',
info: 'green',
warning: 'yellow',
error: 'red'

module.exports = function (config) {
var loggly = config.get('loggly')
// prepare some custom log levels
var customLevels = {
levels: {
debug: 0,
info: 1,
warning: 2,
error: 3
},
colors: {
debug: 'blue',
info: 'green',
warning: 'yellow',
error: 'red'
}
}
}

var handleExceptions = true
if (config.get('test')) {
handleExceptions = false
}
var transports = [
// setup console logging
new (winston.transports.Console)({
var handleExceptions = true
if (config.get('test')) {
handleExceptions = false
}
var transports = [
// setup console logging
new (winston.transports.Console)({
level: 'debug',
levels: customLevels.levels,
handleExceptions: handleExceptions,
prettyPrint: true,
colorize: true
})
]


// setup logging to loggly
if (config.get('loggly')) {
transports.push(new winston.transports.Loggly({
subdomain: 'nisaacson',
inputToken: loggly.inputToken,
handleExceptions: handleExceptions,
level: 'info',
prettyPrint: true,
json: true
// colors: customLevels.colors
}))
}

// create the logger
var logger = module.exports = new (winston.Logger)({
level: 'debug',
levels: customLevels.levels,
handleExceptions: handleExceptions,
prettyPrint: true,
colorize: true
handleExceptions: true,
transports: transports,
colors: customLevels.colors
})
]


// setup logging to loggly
if (config.get('loggly')) {
transports.push(new winston.transports.Loggly({
subdomain: 'nisaacson',
inputToken: loggly.inputToken,
handleExceptions: handleExceptions,
level: 'info',
prettyPrint: true,
json: true
// colors: customLevels.colors
}))
// set the coloring
winston.addColors(customLevels.colors)
return logger
}

// create the logger
var logger = module.exports = new (winston.Logger)({
level: 'debug',
levels: customLevels.levels,
handleExceptions: true,
transports: transports,
colors: customLevels.colors
})

// set the coloring
winston.addColors(customLevels.colors)

module.exports = logger
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "loggly-console-logger",
"version": "1.0.3",
"version": "1.0.4",
"description": "Winston-based logger that outputs to the console and loggly if the loggly input token is set in the nconf object",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions test/logger-test.js
@@ -1,3 +1,7 @@
var config = require('nconf').defaults({
test: true
})

var logger = require('../index')
describe('Logger test', function () {
it('should log to console', function () {
Expand Down

0 comments on commit ffd057f

Please sign in to comment.