Best way to show line number of logging line? #61

mrjcleaver opened this Issue Mar 13, 2012 · 5 comments


None yet
4 participants

In log4js-node, is there a way to automatically show the file and line number that logs a message?

I found - should I do something custom like this?

Sorry, I did look through existing tickets and documentation but my search came up no hits. It just seems like an obvious thing to want.

Best, Martin.


nomiddlename commented Mar 13, 2012

There's nothing to do this at the moment, but I'd be happy to accept a pull request that implemented it.


nomiddlename commented Mar 27, 2012

Looks like this module would be an easy way to implement it, if anyone is interested:

vjpr commented May 26, 2013

This is what I use:

path = require 'path'
stackTrace = require 'stack-trace'

getCallerFile = ->
  frame = stackTrace.get()[8]
  file = path.relative process.cwd(), frame.getFileName()
  dir = path.dirname file
  ext = path.extname file
  base = path.basename file, ext
  line = frame.getLineNumber()
  #method = frame.getFunctionName()
    appenders: [
        type: 'logLevelFilter'
        level: 'TRACE'
          type: 'console'
            type: 'pattern'
            #pattern: "%[%p%] #{"%c".underline.grey} - %m"
            #pattern: "%[%p%] #{"%c".underline} (#{"%x{filename}"}) - %m"
            pattern: "%[%5p%] #{"%x{filename}".grey} - %m"
              filename: getCallerFile

Has anyone tackled a Pull Request using the module proposed by @nomiddlename ? I can try with my still basic Javascript.


nomiddlename commented Nov 1, 2017

PR #580 should fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment