1

log4cxx pattern %l will output the source file name and its path to the log, which makes it uncomfortable to read, if the source file is in in a deep directory, when compiled with a absolute path.

2012-11-20 15:59:14,184 0x7f7ae90e27c0 TRACE fogs.common (/home/jw/fogs/d_common/net/inc/amf3conn.hpp:158) - Entering setCallbackObjBuffer

is there a way to only output the amf3conn.hpp:158 in the log, to shorten the log line?

NeilJiang
  • 223
  • 1
  • 3
  • 10

1 Answers1

2

I do not think that this is possible out-of-the-box. According to the API docs, you can use either %l or %F, but %F only discards the line number and still prints the path.

You have two alternative choices:

  • Subclass PatternLayout and implement your own handling of location conversion, discarding the path and only using the filename
  • Or use the length modifier to set a maximum length for the location, something like %.20l which would result in inc/amf3conn.hpp:158 in your case. If you choose the length of your longest source file name, you get the complete file name in any case (possibly prepended with a part of the path)
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123