ch.claudio.lib
Class Log

java.lang.Object
  extended by ch.claudio.lib.Log

public class Log
extends java.lang.Object

Method to create a logger the way I like. It will set up a formatter writing output in the form:

 2008-01-02T12:58:04+0000 INFO "[thread] at in.my.package.MyClass.method(MyClass.java:104)"
  This is the message.
 

The last part of the first line is in the same format as in exceptions so e.g. in eclipse you can click on it and you will be shown the position in the code.

Version:
$Id: Log.java 249 2008-04-25 20:03:14Z claudio $
Author:
Claudio Nieder

Copyright (C) 1997-2008 Claudio Nieder <private@claudio.ch>, CH-8610 Uster

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Field Summary
static java.text.SimpleDateFormat iso8601
          SimpleDateFormatter for ISO 8601 output
 
Constructor Summary
Log()
           
 
Method Summary
static java.lang.String classloaderChainToString(java.lang.Class<?> c)
          Given a class return a string containing that class class loader chain.
static java.util.logging.Logger createLogger(java.lang.Class<?> c)
          Create a new logger instance which logs to the console in my desired format.
static java.util.logging.Logger createLogger(java.lang.Class c, java.lang.String[] skipMethods)
          Create a new logger instance which logs to the console in my desired format.
static java.lang.String locateMyCall(java.lang.String packageName, java.lang.String[] skipMethods)
          Find in the stack trace the first entry which point to a method in a the package which set up the logger.
static void main(java.lang.String[] args)
          Print license.
static java.lang.String memoryUsageToString()
          Report some memory usage statistics gathered from the java.lang.management classes.
static java.lang.String propsToString()
          Store system properties into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iso8601

public static final java.text.SimpleDateFormat iso8601
SimpleDateFormatter for ISO 8601 output

Constructor Detail

Log

public Log()
Method Detail

createLogger

public static java.util.logging.Logger createLogger(java.lang.Class c,
                                                    java.lang.String[] skipMethods)
Create a new logger instance which logs to the console in my desired format. The skipMehtods works as in locateMyCall.

Parameters:
c - Class from which the name is extracted.
skipMethods - method names to skip when finding method name to display.
Returns:
logger

createLogger

public static java.util.logging.Logger createLogger(java.lang.Class<?> c)
Create a new logger instance which logs to the console in my desired format.

Parameters:
c - Class from which the name is extracted.
Returns:
logger

locateMyCall

public static final java.lang.String locateMyCall(java.lang.String packageName,
                                                  java.lang.String[] skipMethods)
Find in the stack trace the first entry which point to a method in a the package which set up the logger. It will also skip any methods containing a string found in skipMethods. For this it is tested if the full method name (package.Class.method) contains any of the elements in skipMethods.

Parameters:
packageName - own package name needed to know which is the first entry belonging to it
skipMethods - methods to skip or null
Returns:
[thread] package.class.method(class:line)

propsToString

public static java.lang.String propsToString()
Store system properties into a string.

Returns:
multiline string with all properties

classloaderChainToString

public static java.lang.String classloaderChainToString(java.lang.Class<?> c)
Given a class return a string containing that class class loader chain.

Parameters:
c -
Returns:
class loader chain

memoryUsageToString

public static java.lang.String memoryUsageToString()
Report some memory usage statistics gathered from the java.lang.management classes. I decided to report only the peak usage as it is intended to give me an idea on how low I can set the memory boundaries and yet keep the application running.

Code Cache committed indicates the smallest value allowed for -Xmaxjitcodesize in server mode though in client mode a smaller than indicated value was possible.

The Option -Xmx or -XX:MaxHeapSize has an effect on Tenured, Survivor and Eden Peak max. It can be set as low as 1 byte (0 byte for the XX option) as a minimum of approximately 6 MByte is enforced automatically. The chosen size seems to be somehow rounded to 1 MByte steps. It can be lowered using the -XX:OldSize option.

The Option -XX:MaxPermSize allows to reduce the Perm Gen max usage. It can be set as low as 0 Byte as a minimum of 16 MByte in server and 12 MByte in client mode is enforced. The chosen size seems to be somehow rounded to 2 MByte steps. It can be lowered using the -XX:PermSize option.

The committed virtual memory value shown at the end is the memory requested from the operating system. This is relevant e.g. when using a java on a Virtuozzo virtual server, as this is how much is accounted when determining the total RAM need of all applications.

The lowest virtual memory usage I managed to achieve until now with Sun JDK 1.6.0_05 is 25'468'928 Byte in server mode using the options -server -Xshare:off -XX:MaxPermSize=0 -XX:MaxHeapSize=0 -Xss48129 -XX:OldSize=65536 -XX:PermSize=1048576 -Xmaxjitcodesize2359296 and 20'336'640 Byte in client mode using the options -client -Xshare:off -XX:MaxPermSize=0 -XX:MaxHeapSize=0 -Xss48129 -XX:OldSize=65536 -XX:PermSize=1048576 -Xmaxjitcodesize323585

This was done with a class which had a main method containing just the code of this method and nothing else. One risks to run into OutOfMemoryError problems using these settings on real world applications.

There is another small gain (100k in server and just 5k in client mode) made possible by shifting memory from new (eden+survivor) to old (tenured) generation. One can accomplish this by limiting the new generation using either the -Xmn or -XX:NewSize option. One has to compensate the stolen memory by adding it to the -XX:OldSize option so that the sum is 1 MByte. The gain does not happen gradually, but all at once when the new generation size falls below 256 kByte.

As a side note, execution took about 150ms wall clock time on a 2.4GHz Pentium-4 mobile processor, this would be the overhead in starting an application with the above options.

Adding the -Xcomp option to force hotspot to compile all classes before application execution would make no change in client mode and increase execution time to 2 second and memory usage to 29.5 MByte in server mode.

Returns:
string with information about used memory

main

public static void main(java.lang.String[] args)
Print license.

Parameters:
args - ignored