Log4cxx and full file paths when used with CMake

1.6k views Asked by At

I'm using Log4Cxx for logging and I'd like to use the %l directive in order to see where is the log trace (filename and line number). The problem I have is that I'm also using CMake that provides full path names to the compiler. This causes that log columns aren't aligned any more and they are now difficult to read since the log4cxx uses the __FILE__ preprocessor macro for determining that information.

Does anyone know any workaround? I'd like to specify for instance either of getting only the "filename.cpp" or better with a nesting parameter, for instance 2 nesting will be "module/submodule/filename.cpp". It seems that by design CMake works with the full path philosophy so I think that this could be solved either by using an unknown to me preprocessor directive or to trick Log4CXX some way.

1

There are 1 answers

0
DLRdave On BEST ANSWER

Looks like you could try using a "ConversionPattern" to at least specify a maximum width for the filename output of log4cxx:

http://logging.apache.org/log4cxx/apidocs/classlog4cxx_1_1_pattern_layout.html

Or do a "find on page" of ConversionPattern here for a config file example:

http://logging.apache.org/log4cxx/index.html

According to the docs, you should get the rightmost characters when you specify a maximum width. Maybe that's a close enough approximation to what you're seeking here.

CMake always passes full path source file names to the compiler so that debug symbols reference the correct source files (for one thing). It's simply easier to guarantee that things work everywhere on all platforms using the full path names.