I would recommend adding it as a special Lookup just like hostname is.  Then in 
your pattern layout you just need to specify the header as ${java-version} or 
${java-short-version}, etc.

Ralph

On Sep 18, 2014, at 9:51 AM, Gary Gregory <[email protected]> wrote:

> 
> I would like the start of my logs to start with the same information "java 
> -version" provides. 
> 
> On the console, "java -version" says:
> 
> java version "1.8.0_20"
> Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
> Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
> 
> I cook this up manually now from system properties but it sure would be nice 
> to ask Log4j to do it for me since 'java -version' is something I am sure we 
> are all used to seeing.
> 
> This could be done with special pre-built Message classes and % markers I can 
> also add to the header of a file (or any) appender.
> 
> I could see a:
> 
> JavaShortVersionMessage and %JavaShortVersion produce:
> java version "1.8.0_20"
> 
> JavaJreVersionMessage %JavaJreVersion produce:
> 
> Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
> 
> JavaVmVersionMessage and %JavaVmVersion produce:
> Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
> 
> In code I could say:
> 
> logger.debug(new JavaShortVersionMesssage());
> logger.debug(new JavaJreVersionMessage());
> logger.debug(new JavaVmVersionMessage());
> 
> In a file appender I could say header="My 
> App%n%JavaShortVersionMessage%n%JavaJreVersionMessage%n%JavaVmVersionMessage%n"
> 
> Or maybe we could have someway to break a header into >1 log event.
> 
> Thoughts?
> 
> Gary
> 
> -- 
> E-Mail: [email protected] | [email protected] 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

Reply via email to