I created a wrapper for the logger because I did not want to use a global:
var express = require('express');
var app = express();
var log = require('bristol');
var debugMode = app.get('env') == 'development';
// Bristol provides error, warn, info, debug, and trace severity levels
if ( debugMode ) {
log.addTarget('console')
.withFormatter('human');
log.addTarget('file', {file: '/logs/debug.log'})
.withLowestSeverity('debug')
.withHighestSeverity('debug')
.withFormatter('human');
}
// Always log errors
log.addTarget('file', {file: '/logs/error.log'})
.withLowestSeverity('warn')
.withHighestSeverity('error')
.withFormatter('commonInfoModel');
module.exports = log;
In my router index.js, I wanted to get the log and set a global with the function name
var log = require('../lib/log.js');
log.addGlobal('function', "router.post('/my/router/path')");
However, I get a TypeError
TypeError: Object #<Bristol> has no method 'addGlobal'
at renderView (/Users/promise/WebstormProjects/demo/routes/index.js:7:9)
at Object.router.get.renderView.title [as handle] (/Users/promise/WebstormProjects/demo/routes/index.js:34:5)
at next_layer (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/route.js:107:5)
at proto.handle.c (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/index.js:205:24)
at Function.proto.process_params (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/index.js:269:12)
at next (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/index.js:199:19)
at Function.proto.handle (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/index.js:151:3)
at Layer.router (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/index.js:24:12)
at trim_prefix (/Users/promise/WebstormProjects/demo/node_modules/express/lib/router/index.js:240:15)
I do not believe it has anything to do with my wrapper as I get the same error with
var log = require('bristol');
log.addGlobal('function', "myFunction()");
Oh goodness-- excellent catch! The error here is in the documentation. This function is not called addGlobal, but rather setGlobal. I'm pushing a new README now with this change.
I created a wrapper for the logger because I did not want to use a global:
In my router index.js, I wanted to get the log and set a global with the function name
However, I get a TypeError
I do not believe it has anything to do with my wrapper as I get the same error with