1

I am newbee to node.js and using log4js for logging in my example application.

Following is my code.

logger.js file has following code.

var log4js = require('log4js');
log4js.configure({
     appenders: [{ type: 'console' },
                 { type: 'file', filename: 'temp.log', category: 'debug'}
                ]
});

var logger = log4js.getLogger('debug');

exports.debug = function(message){
    logger.debug(message);
};

Now my example server code follows.

var app = require('express')();
var log = require('./logger.js);
var server = app.listen(9090,'127.0.0.1',function(){
    log.debug('Example server listening at http://%s:%s', server.address().address, server.address().port)
});

It runs fine. But I am getting " Example server listening at http://%s:%s " instead of "Example server listening at http://127.0.0.1:9090"

Kindly let me know a solution so that I can get a right output.

Thanks in advance!

1 Answers1

1

Javascript (and Node implicitly) does not support that sort of string formatting. Just append strings like you would normally do

log.debug('Example server listening at http://' + server.address().address + ':' + server.address().port)
Dan Moldovan
  • 3,576
  • 2
  • 13
  • 24
  • I agree with you Dan. But this behavior is seen only when I use exporting. Instead, if I stuff entire content of logger.js in example.js and pass "Example server listening at http://%s:%s', server.address().address, server.address().port)" to the logger.debug() function, I get the desired result. – user2669956 May 22 '15 at 11:32