|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectdk.rode.thesis.meta.log.AbstractLog
public abstract class AbstractLog
An abstract log implements the basic traits of
any Log implementation.
The logger is not thread-safe!
| Field Summary | |
|---|---|
private boolean |
active
True if active, i.e. logs messages, false if inactive. |
private Class<?> |
clazz
The class to which this log is associated, if any. |
private boolean |
flushed
True if the last logged message ended with a newline, false if not. |
private AtomicInteger |
lineNumber
If not null, the line number representing the current value is logged. |
| Constructor Summary | |
|---|---|
protected |
AbstractLog(Class<?> clazz,
boolean active,
AtomicInteger lineNumber)
Constructor. |
| Method Summary | |
|---|---|
Log |
error(Object... messages)
Logs each part of an error message supplied in messages
with this log as is, no trailing new line or white space
inserted between message parts, but with a single new line
character after the last part as well as a prefix
indicating the message represent an error message. |
private void |
forceNewLine()
Prints a new line if this log is not flushed. |
protected CharSequence |
format(Object object)
Formats the object supplied as object into
a char sequence representation that can be logged. |
int |
getLineNumber()
If this log logs line numbers, the current line number is returned; otherwise 0. |
String |
getPrefix()
Returns the prefix of this log that will be prefixed to all log messages starting at a new line. |
static String |
getPrefix(Class<?> clazz)
Returns the current prefix to prefix any log message based on the class supplied as clazz. |
Log |
heading(Object... heading)
Logs each part of a heading supplied in messages
with this log as is, no trailing new line or white space
inserted between heading parts, but with a single new line
character after the last part, underscored on the next log
line. |
boolean |
isActive()
Returns true if this log is active, i.e. logs messages, false if inactive. |
protected abstract void |
log(Object... messages)
Performs the actual logging of the messages supplied as messages with no new line postfixed. |
Log |
print(boolean condition,
Object... messages)
Logs each message part supplied in messages
with this log as is, no trailing new line or
white space inserted between messages, if and only
if condition is true. |
Log |
print(Object... messages)
Logs each message part supplied in messages
with this log as is, no trailing new line or
white space inserted between messages. |
Log |
println(boolean condition,
Object... messages)
Logs each message part supplied in messages
with this log as is, no trailing new line or
white space inserted between messages, if and only
if condition is true, but always with a
single new line character after the last part. |
Log |
println(Object... messages)
Logs each message part supplied in messages
with this log as is, no trailing new line or
white space inserted between messages, but with a
single new line character after the last part. |
Log |
setActive(boolean active)
If active is true, this log is set to active, i.e. to
log messages. |
String |
toString()
Returns the string representation of this log. |
Log |
warn(Object... messages)
Logs each part of a warning message supplied in messages
with this log as is, no trailing new line or white space
inserted between message parts, but with a single new line
character after the last part as well as a prefix
indicating the message represent a warning message. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private boolean active
private Class<?> clazz
Null indicates the global log.
private boolean flushed
private final AtomicInteger lineNumber
If used, even empty lines logged will have a line number.
Default false.
| Constructor Detail |
|---|
protected AbstractLog(Class<?> clazz,
boolean active,
AtomicInteger lineNumber)
Line numbers are logged if lineNumbers is not null.
clazz - The class to which this log is associated, if any.
Null indicates global log.active - True if this log is initially active, false if not.lineNumber - The line number values; can be null, in which
case line numbers are not generated.isActive()| Method Detail |
|---|
public Log error(Object... messages)
Logmessages
with this log as is, no trailing new line or white space
inserted between message parts, but with a single new line
character after the last part as well as a prefix
indicating the message represent an error message.
A part that is null is logged as the string null.
Example (default log):
error("This", "is ", " an ", "error"):
MAIN:xxx:123:: > ERROR - Thisis an error(newline)
Where xxx is the name of the member invoking the
error method and 123 the line number.
error in interface Logmessages - The message parts; can be null, corresponding to
a single new line being printed.
private void forceNewLine()
protected CharSequence format(Object object)
object into
a char sequence representation that can be logged.
object - The object; can be null.
public int getLineNumber()
Log
getLineNumber in interface Logpublic String getPrefix()
Log
getPrefix in interface Logpublic static final String getPrefix(Class<?> clazz)
clazz. The prefix will include the name of the member and line number of the calling context that issued the original log request.
clazz - The current class; can be null.
CallerClasspublic Log heading(Object... heading)
Logmessages
with this log as is, no trailing new line or white space
inserted between heading parts, but with a single new line
character after the last part, underscored on the next log
line.
A message that is null is logged as the string null.
Example (default log):
heading("This", "is ", " a ", "heading"):
(newline)
MAIN:xxx:123:: Thisis a heading(newline)
MAIN:xxx:123:: =================(newline)
(newline)
(newline)
Where xxx is the name of the member invoking the
heading method and 123 the line number.
heading in interface Logheading - The message parts; can be null, corresponding to
a single new line being printed (no underscore).
public final boolean isActive()
Log
isActive in interface Log
protected abstract void log(Object... messages)
throws IOException
messages with no new line postfixed.
All messages part are assumed to have a meaningful
toString() representation and are not null,
and there is no need for explicit formatting.
messages - The messages to log; never null.
IOException - In case an exception occurs while logging.
public final Log print(boolean condition,
Object... messages)
Logmessages
with this log as is, no trailing new line or
white space inserted between messages, if and only
if condition is true.
A part that is null is logged as the string null.
Example (default log):
i = 1; .. print(i > 0, "This", "is ", "message #", new Integer(42), "!"): MAIN:xxx:123:: Thisis message #42! .. i = 0; .. print(i > 0, "This", "is ", "message #", new Integer(42), "!"): (nothing logged)Where
xxx is the name of the member invoking the
print method and 123 the line number.
print in interface Logcondition - The condition to use.messages - The message parts; can be null, which will not
print anything.
public final Log print(Object... messages)
Logmessages
with this log as is, no trailing new line or
white space inserted between messages.
A part that is null is logged as the string null.
Example (default log):
print("This", "is ", "message #", new Integer(42), "!"):
MAIN:xxx:123:: Thisis message #42!
Where xxx is the name of the member invoking the
print method and 123 the line number.
print in interface Logmessages - The message parts; can be null, which will not
print anything.
public final Log println(boolean condition,
Object... messages)
Logmessages
with this log as is, no trailing new line or
white space inserted between messages, if and only
if condition is true, but always with a
single new line character after the last part. Hence,
if condition is false, the effect is
equivalent to println().
A part that is null is logged as the string null.
Example (default log):
i = 1; .. println(i > 0, "This", "is ", "message #", new Integer(42), "!"): MAIN:xxx:123:: Thisis message #42!(newline) .. i = 0; .. println(i > 0, "This", "is ", "message #", new Integer(42), "!"): (newline logged only)Where
xxx is the name of the member invoking the
println method and 123 the line number.
println in interface Logcondition - The condition to use.messages - The message parts; can be null, corresponding to
a single new line being printed.
public final Log println(Object... messages)
Logmessages
with this log as is, no trailing new line or
white space inserted between messages, but with a
single new line character after the last part.
A part that is null is logged as the string null.
Example (default log):
println("This", "is ", "message #", new Integer(42), "!"):
MAIN:xxx:123:: Thisis message #42!(newline)
Where xxx is the name of the member invoking the
println method and 123 the line number.
println in interface Logmessages - The message parts; can be null, corresponding to
a single new line being printed.
public final Log setActive(boolean active)
Logactive is true, this log is set to active, i.e. to
log messages.
setActive in interface Logactive - True to (re-)activate, false to disable.
public String toString()
toString in class Objectpublic Log warn(Object... messages)
Logmessages
with this log as is, no trailing new line or white space
inserted between message parts, but with a single new line
character after the last part as well as a prefix
indicating the message represent a warning message.
A part that is null is logged as the string null.
Example (default log):
warn("This", "is ", " a", "warning"):
MAIN:xxx:123:: > WARN - Thisis awarning(newline)
Where xxx is the name of the member invoking the
warn method and 123 the line number.
warn in interface Logmessages - The message parts; can be null, corresponding to
a single new line being printed.
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||