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 Answer 1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.