Logging

From WIKI@COMJAT.NET

Jump to: navigation, search

Contents

Introduction

It's Java! Yet another logger system for your java apps! Take a close look at it: You may attach your favourite set of loggers to COMJAT.NET's logger, and you still use only one API. You may receive events containing log messages (Who? Where? What? Which category? How important? ...) and do any filtering. You may log into some file or to standard out or feed a SWING dialog. In the Logging howto you'll find an example with source codes which guides you step-by-step on how to use the COMJAT.NET Logging.

Author

Siegfried Steiner User:steiner

Yet another logger

All runtime-information generated in the COMJAT.NET software and the applications set on top of these systems use the Java Log-Service.

Log architecture

The Log-Service consists of Java classes being divided into a public and a private section: The private section is used to configure the Log-Service, and the public part is used to Log runtime-information by an application: A system or an application is usually provided with the public part of the Log-Service. The private part is created once, and all systems created thereafter are provided with the public part of the same Log-Service. The public part of the Log-Service is being provided by the private part of the Log-Service (i.e. created in the object representing the private Log-Service).

The Log-Service centralizes the collection, visualization, storage and distribution of runtime-information. Having access to the private part of the Log-Service, one can decide which messages are actually to be logged, and what has to happen with the logged messages. The messages can be logged into a file, to the standard output or be visualized by s Windows-GUI.

Log-Levels

The system using the public part of the Log-Service provides a Log-message (human readable text), a Log-level, a Log type and information about the Log-source, being the method name, class name, package name of the Log-source).

The Log-level is the message?s priority. It states the seriousness of the message. The private part can be configured in order to Log only messages of a given priority level. For example, only messages which are as serious as warnings and higher are to be Logged, no matter what Logs are generated by the public part of the Log-Service.

Here a list of the Log-Levels (Level - Name - Description):

0 - PANIC   > The subsystem probably has to be halted or is halted
1 - ERROR   > A malfunction occurred which does not cause a crash
2 - WARNING > Something happened which can be ignored
3 - STATUS  > Standard runtime information
4 - DETAIL  > Detailed runtime information
5 - DEBUG   > Information for debugging purposes only

Figure 1: The log levels and their meaning

The Log-level values are pre-defined meaning that only values between 0 and 5 are allowed to be used as Log-level. Log-Types

The Log-type is used to categorize the intention of the message (i.e. performance, memory usage) ? the type can be used to filter only the messages of interest. Messages of type performance are used to identify inefficient methods or messages of type memory are used to track memory leaks. In comparison to the Log-level, the Log-types may be defined by the application using the Log-Service.

Here is the list of Log-Types (Type - Description):

RUNTIME     > Runtime information of no special purpose
PERFORMANCE > Performance issues are observed
MEMORY      > Memory usage issues are observed
NETWORK     > Networking issues are observed
ERROR       > Error issues are to be observed

Figure 2: The pre-defined log types

(More types may be added at runtime time)

The types stated in the table are suggestions, whose constant definitions (such as public static final String LOG_TYPE_RUNTIME = "someRuntimeLogType") have been defined in an interface belonging to the Log-Service as those Log-types are of special interest. An application may dynamically add new Log-types, depending on the categories needed to be observed.

Log-Location

The logger expects you to provide the exact location of where the log message was created. The exact location in this context means: In which package, which class and which method was the message logged?

In order for you to create this information automatically - to keep the location up-to-date (even if your class name, the method name or the package changed) - there is a tool managing special keywords in your source-code. Please contact me for more information on this tool.

Finishing it off

The Log-System is the one logger used by the COMJAT.NET systems. It is very unified: You may add your own flavour or attach and migrate other loggers. COMJAT.NET thereby provides the means to bring different worlds under one control.

Using the event driven Log-System you are able to do about anything with your log messages: Collect them, send them by E-Mail, show a dialog on special Log-Types, push them into another logger, do special filtering of the messages, and so on!

There is a graphical fronted of the Log-System enabling the comfortable examination of the Log-Messages (which package, which class, which method, what level and type). Please contact me for more information on this tool.

In order for the Logger to run you need the COMJAT.NET APIs. They are free and may be downloaded in the download section. Include the JAR-Files in your classpath and try the example below!

Further reading

The Logging howto provides you with a step-by-step guide on how to use the COMJAT.NET Logging in your own applications.

Personal tools