1

I want to format the log4j elapsed running-time, %r parameter, in something readable like:

  • [00:36:25.844] and [01 13:35:25.844]
  • [HH:mm:ss.SSS] ... [dd HH:mm:ss.SSS]

The format:

  • %r{HH:mm:ss,SSS}

Didn't work, it just printed the %r time and the literal, "{HH:mm:ss,SSS}".

Alternatively I already have an execution time-stamp string method, is there a way to provide just a custom format without needing to write a custom appender (or equivalent)?

similar questions:

Community
  • 1
  • 1
will
  • 4,799
  • 8
  • 54
  • 90

1 Answers1

0

You need to define your own layout, or at least your own character. There are good blog articles on how to do that. There is also MDC, which (sadly) won't work in your case, becuase the information is evaluated on class init only once.

But if you use the slf4j API, you can switch over to logback and write your own converter. This is even more easy to do than overriding an existing apache log4j PatternLayout.

Benjamin Marwell
  • 1,173
  • 1
  • 13
  • 36