|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.andynaz.log.Logger
public class Logger
Base logger. This class is the root of all the logger jerarchy. A logger actually logs all the events.
Each logger has a set of attributes related to haw it logs the events (for
instance, FileLogger
has a File object to where write the logs).
A logger should have also methods related to this set of attributes.
In addition to this members, each logger has also a name, used in the log
prefix (useful to distinguish which logger do a log).
Every log is written with a prefix, which is returned by the getPrefix()
method.
Logs are written using the various log() methods: every method, before writing the log, check if the log level if enough to write the log.
Sub-classes of this logger can change the way a log is written (for
instance, in a file or on a database), only changing the log(String, Level)
method. For other reasons, like efficiency, aother
methods can be overridden.
This logger uses the System.out
.
Field Summary | |
---|---|
protected SimpleDateFormat |
dateFormat
Indicates the format of the date. |
protected Level |
level
Indicates the level of the logging. |
protected String |
name
Name of the logger. |
protected String |
separator
Indicates the separator to use in the prefix of the logs. |
protected boolean |
withDate
Indicates if the date has to be used in the prefix of the log. |
protected boolean |
withLevel
Indicates if the level code has to be used in the profix of the log. |
Constructor Summary | |
---|---|
Logger()
Creates a logger. |
|
Logger(Config conf)
Creates a logger with a configuration. |
|
Logger(String name)
Creates a logger with a name. |
|
Logger(String name,
Config conf)
Creates a Logger with a name and a specified configuration. |
Method Summary | |
---|---|
protected String |
getDate()
Returns a string with the date. |
protected String |
getPrefix()
Returns the prefix to be written before the log. |
void |
log(Exception e)
Writes the log of an exception. |
void |
log(Exception e,
Level level)
Writes the log of an exception with a specificied level. |
void |
log(String log)
Writes a log. |
void |
log(String log,
Level level)
Writes a log with a specified level. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected String name
protected boolean withDate
If the value is 'true', the prefix starts with "date+separator"
protected boolean withLevel
protected Level level
Level.INFO
.
Only the logs with a level higher than this value will be logged.
protected SimpleDateFormat dateFormat
SimpleDateFormat
. Dafaule value is
"yy-MM-dd HH:mm:ss".
protected String separator
Constructor Detail |
---|
public Logger(String name, Config conf)
Properties are used to construct the attributes of the logger. If error occour (for instance, the format for the date is not correct), no exception is thrown and the default value is used.
The properties taken from the Config object are:
SimpleDateFormat
objectLevel
enum constants
name
- name of the loggerconf
- logger configurationpublic Logger(String name)
name
- name of the loggerpublic Logger(Config conf)
conf
- configuration of the loggerpublic Logger()
Method Detail |
---|
public void log(String log, Level level)
log
- log to be writtenlevel
- log levelpublic void log(String log)
Level.INFO
.
log
- log to be writtenpublic void log(Exception e)
Level.INFO
.
e
- exception to be loggedpublic void log(Exception e, Level level)
It is written the exception type (with the message of the exception, if present) and the stack trace
e
- exception to be loggedlevel
- log levelprotected String getPrefix()
The prefix is
[date+sep][name+sep]where each part is optional (depends on the logger configuration).
Note: the log prefix returned does not include the level code, which has to be included in the log methods.
protected String getDate()
dateFormat
values.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |