java - Locale <=> Time/Date format in Tomcat logs? -


i can't seem change locale / date format in tomcat logs when running eclipse. it's using 12-hour clock , want use 24-hour clock instead (language english, want). here's have tried far:

  • setting lang , lc_all environment variables en_gb in tomcat's launch configuration
  • adding -duser.language=en -duser.region=gb vm options in tomcat's launch configuration
  • adding -duser.language=en -duser.region=gb eclipse's eclipse.ini
  • setting -duser.language=en -duser.region=gb default vm arguments in jre configuration

if run tomcat shell, works expected adding -duser.language=en -duser.region=gb %java_opts% in bin\catalina.bat - example outlined here - doesn't affect tomcat when running within eclipse, of course. (erratum: couldn't reproduce , have assume erroneously ran tomcat java 6 instead of 7)

used software: tomcat 7.0.54, oracle jdk 1.7.0_60 (64-bit), windows 8 (64-bit)


update: michael-o's answer, made aware of change in java's locale-resolution of java 7. indeed, going java 6 fixes problem , gives me 24-hour clock - not feasible current project.

i've not been able achieve same java 7. supposedly, can return old locale-resolution setting system property sun.locale.formatasdefault true, that not seem affect time display in tomcat 7's logging @ all. after while found this bug in it's stated clear:

(...) lost ability decide on 24hour vs 12hour time depending on locale, gained ability override default format providing format string java.util.logging.simpleformatter.format property in logging.properties.

thus, seems, defining format string manually (only?) way go, , michael-o suggested that, i'm accepting answer.

after delving madness java.util.formatter's syntax, have settled format string, needs put in vm options in tomcat's launch configuration:

-djava.util.logging.simpleformatter.format="%1$ty%1$tm%1$td_%1$th%1$tm%1$ts_%1$tl %4$4.4s %3$s %5$s %n" 

output:

151003_195915_359 info org.apache.coyote.http11.http11protocol starting protocolhandler ["http-bio-8080"]  151003_195915_375 info org.apache.coyote.ajp.ajpprotocol starting protocolhandler ["ajp-bio-8009"]  151003_195915_375 info org.apache.catalina.startup.catalina server startup in 1280 ms 

alternatively shorter, iso 8601 timestamps use:

-djava.util.logging.simpleformatter.format="%tft%<tt.%<tl %4$4.4s %3$s %5$s %n" 

output:

2015-10-03t19:37:03.703 info org.apache.coyote.http11.http11protocol starting protocolhandler ["http-bio-8080"]  2015-10-03t19:37:03.703 info org.apache.coyote.ajp.ajpprotocol starting protocolhandler ["ajp-bio-8009"]  2015-10-03t19:37:03.703 info org.apache.catalina.startup.catalina server startup in 1189 ms  

you have been hit this change in java 7.

the solution see custom formatter iso 8601.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -