Using LogAgent

The LogAgent can be used by adding the LogAgent as javaagent to the java command line. The simplest form is by adding -javaagent:logagent-0.2.jar to the java command line. The full java command could look something like: java -javaagent:logagent-0.1.jar test.Main
The LogAgent will per default write its log in xml format to the file logagent.xml in the current directory.

It is possible to add several parameters to the logagent in order to modify its behaviour:

  • output
  • include
  • exclude
  • exmethod
  • config

output

It is possible to specify that the output has to be logged to the file otherfile.txt by using the output command -javaagent:logagent-0.1.jar=output=otherfile.txt. Both .txt and .xml are recognized as special extensions and will lead to text based or xml based logging output. The result for other extensions are unspecified.

include

It is possible to specify the package or class to be logged on the command line as well, in that case the include command can be used. Specifying -javaagent:logagent-0.1.jar=include=net.famkruithof can be used to only log the package net.famkruithof (and all subpackages).
The first include command implicitly excludes all unspecified packages or classes.

exclude

The same way specific packages can be excluded as well using the exclude command. -javaagent:logagent-0.1.jar=exclude=net.famkruithof can be used to not log the package net.famkruithof (and all subpackages).

exmethod

Specific methods can be excluded using the exmethod command. -javaagent:logagent-0.1.jar=exmethod=toString will make sure the toString method is not logged in any class.

config

Finally it is possible to specify an configuration file containing a full replacement configuration: Using the config command an alternative base configuration is selected. The -javaagent:logagent-0.1.jar=config=myConfig will completely override the default configuration with the settings in the file myConfig. All other commands only adds (exclude / include / exmethod) to the base configuration, or modifies the base configuration (output).

Configuration file

The configuration file for the LogAgent can be used to specify what has to be logged, and what doesn't have to be logged. In the configuration file the following items can be used:

  • output
  • include
  • exclude
  • exmethod

Every command has to be on its own line. Comments in the file should be on separate lines that start with #.

When writing an own config file you have to keep in mind that the most specific match wins. If the package foo is excluded, and the package foo.bar is included (and no other packages within foo are excluded or included) the methods of class foo.bar.meetoo.SomeClass will have logging added, while the classes in foo.somewhatelse.SomeOtherClass will not be logged.

In case the configuration file does not contain an output command, and the output command is also not specified on the command line, no output will be produced, unless the java logging configuration has some logging action for the logagent logger. (Currently everything is logged at the FINER level.)

The default configuration

# default configuration
exclude java
exclude javax
exclude net/famkruithof/logagent
exclude sun
exclude org/apache/bcel
exclude com/sun
exclude org/ietf/jgss
exclude org/omg
exclude org/w3c/dom
exclude org/xml/sax
exclude org/omg/CORBA_2_3

output logagent.xml

Please note that logging inserted by the logagent is disabled while logging inserted by the logging agent is being executed to prevent logging loops. Furthermore it may not be possible to add logging during runtime to classes needed by the logagent itself, this because the classes are loaded before the logagent is active. Currently the LogAgent can only add logging to classes that have not been loaded before the logagent is active and classes that are not needed by the logagent to perform its function.

Notes

Note that in order to use the logagent, the bcel-5.2.jar file should be available in the same directory as the logagent.

The index of the LogAgent pages

Download the LogAgent

The Change History of the LogAgent

If you have improvements, contact information on the homepage of this host.
An UUID generator on the web
The uptime of home.famkruithof.net