How to determine file, function and line number?

前端 未结 7 1118
清歌不尽
清歌不尽 2020-11-28 06:14

In C++, I can print debug output like this:

printf(
   \"FILE: %s, FUNC: %s, LINE: %d, LOG: %s\\n\",
   __FILE__,
   __FUNCTION__,
   __LINE__,
   logmessage         


        
7条回答
  •  温柔的废话
    2020-11-28 07:09

    You can refer my answer: https://stackoverflow.com/a/45973480/1591700

    import sys
    print sys._getframe().f_lineno
    

    You can also make lambda function

提交回复
热议问题