5

How to include time format with millisecond precision in Apache Access Log.

I tried to use:

pattern="%h %l %u %{%d/%b/%Y %T}t.%{msec_frac}t %{%z}t "%r" %s %b".

However it does not work.

Kian
  • 1,319
  • 1
  • 13
  • 23
Rakshith R Pai
  • 202
  • 1
  • 5
  • 13
  • I answered assuming you mean tomcat, due to the tomcat tag. But your question is vauge. Considering that there is Apache HTTPD and Apache Tomcat, you should probably clarify the language, the question could apply to either. – Magnus Oct 06 '16 at 13:21

2 Answers2

6

From the AccessLogValve documentation

%{xxx}t xxx is an enhanced SimpleDateFormat pattern

So if you use a pattern of something like %{yyyy-MM-dd HH:mm:ss.SSS}t then it should print milliseconds.

Magnus
  • 7,952
  • 2
  • 26
  • 52
  • 2
    This is likely a moot point for most people at this point in time but versions of Tomcat prior to 7 don't support this pattern syntax. – Yeroc Feb 15 '17 at 23:39
  • @Yeroc people don't always use latest or recent versions, so your point is never moot – asgs Oct 15 '20 at 19:15
2

Apache access logs accept time format with sfrtime format from C standard library. Try something like that:

%{%Y-%m-%d %H:%M:%S.%f}t
gmaslowski
  • 774
  • 5
  • 13