Node.js - getting current filename

后端 未结 8 859
执念已碎
执念已碎 2020-12-13 08:04

How to get current file name, function name and line number?

I want to use it for logging/debugging purpose, equivalent to __FILE__, __LINE__

相关标签:
8条回答
  • 2020-12-13 08:44

    You might also look at console-plus. This adds filename and linenumber to any logging text and has different colours for .log, .info and .error.

    0 讨论(0)
  • 2020-12-13 08:44

    Well, I wanted to use the file name as the tag for the logger so the most straight forward and what I wanted is this:

    __filename.substring(__dirname.length + 1, __filename.lastIndexOf("."))
    
    0 讨论(0)
提交回复
热议问题