src.site.apt.logging.apt Maven / Gradle / Ivy
------
Logging
------
Max Antoni
------
24.03.2007
------
~~ Copyright (c) 2007 Maximilian Antoni. All rights reserved.
~~ This software is licensed as described in the file LICENSE.txt, which you
~~ should have received as part of this distribution. The terms are also
~~ available at http://www.maxantoni.de/projects/eva-properties/license.txt.
~~ NOTE: For help with the syntax of this file, see:
~~ http://maven.apache.org/guides/mini/guide-apt-format.html
What is EvaLog?
EvaLog is a small logging framework, that ships with EvaProperties.
The basic idea behind EvaLog is to have one logger per package and to <>
log the Java class and method names. This results in more readable and user
friendly log files.
Using EvaLog
Create a class called "Log" in each package of your application with the
following content:
+----------------------------------------------------+
import java.util.logging.Logger;
import com.eva.log.EvaLog;
class Log {
static final Logger INSTANCE = EvaLog.create(Log.class);
}
+----------------------------------------------------+
That's is. You can use the logger by accessing <<>> from anywhere
inside the package.
If you want the logger to be configured with a resource bundle, you pass an
optional second argument to the create method:
+----------------------------------------------------+
class Log {
static final Logger INSTANCE = EvaLog.create(Log.class, "messages");
}
+----------------------------------------------------+
The bundle resource needs to be located in the same package as the <<>>
class and must have the file extension ".properties". So in the above example
your bundle file is named "messages.properties".
Configure EvaLog:
If you create a file named "log.eva" and place it in the same package as your
<<>> class, the file will be read when the logger is created and the
contents are used to configure your logger. The properties you can specify are:
* <>: the resource bundle to use.
* <>: override the package for the logger and the resource bundle.
* <>: the <<>> to use. A factory is needed to
create a custom handler instance.
* <>: a list of handlers to use. Will only be checked if there was no
handler property provided. For your convenience, there are two handlers
configured that can be simply referenced with $\{console-handler\} or
$\{file-handler\}.
* <>: the encoding to use.
* <>: the log level to use (FINEST, FINER, FINE, CONFIG, INFO, WARNING or
SEVERE).
* <>: the <<>> to use. A factory is
needed to create a custom formatter instance.
* <>: the <<>> to use. A factory is needed to
create a custom filter instance.
* <>: boolean value to specify wether logging should be
delegated to the parent logger as well. Default is "no".
Defaults:
The default logger provided by EvaLog will be used as the parent logger for
every logger created. Therefore the settings of this logger are inherited by
all other loggers. To give you control over the default logger you can place
a file named "log.eva" in the root of your classpath. This file will be read
when EvaLog is initialized (that is, the class <<>> is loaded).
The contents of the default logger configuration can be the same as for any
other logger. However, they will always have the default properties set as
the "super" properties and therefore inherit the default settings.
Here is the default settings configuration used by EvaLog:
+-------------------------------------------------------------+
encoding: ISO8859-1
level: INFO
dir: "${system.user.dir}/log"
pattern: "eva%g.log"
limit: 10000
count: 5
formatter: ( *com.eva.log.LogFormatter(${prefix})
*com.eva.log.LogFormatter()
)
handler: ${console-handler}
console-handler: *java.util.logging.ConsoleHandler()
file-handler: *java.util.logging.FileHandler(
"${dir}/${pattern}", ${limit}, ${count}
)
useParentHandlers: no
+-------------------------------------------------------------+
© 2015 - 2025 Weber Informatics LLC | Privacy Policy