intel
intel copied to clipboard
console override problems
Hi! Could you make clear console overriding process in README file? I have my express.js app and I'm trying to use intel in my errors handle middleware. My app.js is like that:
// require sime modules // .... var intel = require('intel'); var app = express();
app.use(...); // setting up middlewares
intel.config({ formatters: { 'simple': { 'format': '[%(levelname)s] %(message)s', 'colorize': true }, 'details': { 'format': '[%(date)s] %(name)s.%(levelname)s: %(message)s', 'strip': true } }, handlers: { 'terminal': { 'class': intel.handlers.Console, 'formatter': 'simple', 'level': intel.VERBOSE }, 'logfile': { 'class': intel.handlers.File, 'level': intel.WARN, 'file': 'report.log', 'formatter': 'details' } }, loggers: { 'logger': { 'handlers': ['terminal', 'logfile'], 'level': 'INFO', 'handleExceptions': true, 'exitOnError': false, 'propagate': false }, 'logger.node_modules.express': { 'handlers': ['terminal', 'logfile'], 'level': 'WARN' } } });
var logger = intel.getLogger('logger');
app.use(function(err, req, res, next) { logger.warn(err); next(err); });
intel.console(); // tried to put this at the beginning of the module as well
module.exports = app;
So, when I try to override console - no console messages appears in terminal at all, including logger warns. Without intel.console() logger and console.log works fine.
It's true the docs are a bit vague on this part.
You named your logger logger
but what isn't clear from the docs is that it's expected to match the name of your files and directories in your application.
Example:
yourproject/
app/
app.js
node_modules/
express/
If you want to use intel.console()
to log from app/app.js
, a logger named app
must exit.
Or, if you want to automagically catch from express, a logger matching node_modules.express
must exist.
There are you can do to easier understand this:
- Name your logger
''
and also use this for your console settings:
config = {
console: { src: '' },
logger: {
'': {
- Alternatively, if you are interested to get better insights, temporarily modify the file
node_modules/intel/lib/console.js
and add this line into thedeliver()
function after the call togetLoggerName()
:
process.stdout.write('name => ' + name + '\n');
That should give you some idea what the expected names of the loggers are.