Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


I want to display the file Name in the log statement #197

dsaikumar opened this Issue · 8 comments

4 participants


For every or logger.debug, I need to display the filename in which the following line executed.

Example :

JobWorks.js"Hello Logger");

Actual :
2012-11-05T06:07:19.158Z - warn: getInCompleteJobs in job works

Required :
2012-11-05T06:07:19.158Z - warn JobWorks : getInCompleteJobs in job works


guys please help me, I found a helpful link


subscribe to this, plus my personal suggestion, also display the row from where the log has been executed and from what function name


In my previous reply I said about V8 Javascript Stack Trace API, it is right, now I can get the file name also.

I have writte a function in my js file which will return the file name :

function getFileName(){
var fileName="";
var rowNumber;
var columnNumber;
var currentStackPosition=1; // this is the value representing the position of your caller in the error stack.
throw new Error("Custom Error");
return arguments[1];
Error.prepareStackTrace(e, function(){});

return {"file":fileName,"row":rowNumber,"column":columnNumber};

@dsaikumar dsaikumar closed this
@dsaikumar dsaikumar reopened this

I feel this is ok, If any better suggestions are available please provide me.


This is a really big performance hit. It involves creating an error object and reading the stack trace every time anything is logged. It doesn't belong to winston core. Feel free to create your own logger tho.

@mmalecki mmalecki closed this

thanks for the comment, so how else we can get the file name in the logger


We use a module which wraps around a logger instance. It changes the signature for requiring it.
As a quick example for info:

var logger = require('logger')(module);'My log statement');

Inside your logger module:

var winston = require('winston');

module.exports = function (module) {

  var filename =;
  return {
    info : function (msg, vars) { + ': ' + msg, vars); 

We made it a little more generic to handle other levels of logging, but the basic idea is still the same.

Agree though that it probably doesn't belong in winston source.


way, my opinion is that is a good feature, to be ported in winston as a switch element for logging.
at least this feature, if the posibilty to display the row and the method from where the logging is called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.