How to get actual line number like assert does?

c++

Solution

The macro `__LINE__` contains the current line number.

Note that in order to use it effectively, you have to access it from a macro. If you just call a logging function, and it accesses `__LINE__`, it will report the line number within the logging function. So you might define:

#define LOGINFO(message) (LOG::info((message), __LINE__))

Problem

I want to write logger class and i wonder if it's possible. consider: ``` do_something_funny(&my_cat); LOG::info("just did something funny with his cat"); cout<< LOG::getAllTxt(); ``` output: ``` [0.001s][main.cpp:5] - just did something funny with his cat ``` look at `main.cpp:5`. it was logged from 5 line of this file I should rather use functions in scope, or create singleton object?

Original source