Discussion:
Logging the Java version
Gary Gregory
2014-09-18 16:51:43 UTC
Permalink
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: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Ralph Goers
2014-09-18 17:56:19 UTC
Permalink
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
I would like the start of my logs to start with the same information "java -version" provides.
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.
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)
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
--
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
Matt Sicker
2014-09-18 21:41:26 UTC
Permalink
Wouldn't this all be available through the ${sys:*} lookup variables?
Post by Ralph Goers
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
I would like the start of my logs to start with the same information "java
-version" provides.
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.
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)
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
--
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Matt Sicker <***@gmail.com>
Ralph Goers
2014-09-18 23:38:20 UTC
Permalink
It isn't a system property

Sent from my iPad
Post by Matt Sicker
Wouldn't this all be available through the ${sys:*} lookup variables?
Post by Ralph Goers
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
I would like the start of my logs to start with the same information "java -version" provides.
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.
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)
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
--
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
--
Ralph Goers
2014-09-19 04:24:59 UTC
Permalink
I think I misunderstood you. Yes, you can get java.vm.version and the like as system properties but they may not be completely formatted as Gary wishes.
Post by Ralph Goers
It isn't a system property
Sent from my iPad
Post by Matt Sicker
Wouldn't this all be available through the ${sys:*} lookup variables?
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
I would like the start of my logs to start with the same information "java -version" provides.
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.
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)
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
--
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
--
Loading...