|
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.LogManager
public class LogManager
A simple log manager to create and deliver logs to use, either globally or per unique class.
Per default, the global default log is enabled,
while class specific are disabled.
Its usage and concrete sub-class is hidden as it is accessed
through the LogFactory.
Implementation notes:
This manager utilises the Template Method and
Factory Method
patterns: the create(Class, Class, AtomicInteger) method is the
factory method, which is utilised by the getLog(Class) template method.
In a real-life scenario, there should be such a thing as log-timeout to ensure the file logs are closed properly.
| Field Summary | |
|---|---|
private AtomicInteger |
lineNumber
Line number values, if not null. |
private Map<Class<?>,Log> |
logs
Created logs per class. |
private Class<?> |
type
Class of log to use. |
| Constructor Summary | |
|---|---|
protected |
LogManager()
No-arg constructor. |
protected |
LogManager(Class<T> type,
boolean lineNumbers)
Constructor. |
| Method Summary | |
|---|---|
protected Log |
create(Class<?> clazz,
Class<?> type,
AtomicInteger lineNumber)
Factory method creating the types of log to use. |
Log |
getLog()
Return the default log. |
Log |
getLog(Class<?> clazz)
Returns, and creates if necessary, the log associated with the class supplied as class, if any. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final AtomicInteger lineNumber
private final Map<Class<?>,Log> logs
Null key represents the global log.
Never null.
private final Class<?> type
| Constructor Detail |
|---|
protected LogManager()
protected LogManager(Class<T> type,
boolean lineNumbers)
T - The type of log created by this manager.type - The type of log to use; can be null, in which
case the default type of log is used.lineNumbers - True to log line numbers.| Method Detail |
|---|
protected Log create(Class<?> clazz,
Class<?> type,
AtomicInteger lineNumber)
throws Exception
Override this for different behaviour.
clazz - The class to associate the created log with, if any;
can be null, i.e. default log.type - The type of log to use; never null.lineNumber - Line number values; can be null.
Log instance; never null.
Exception - In case the creation fails (a default log
will be created in its place).public final Log getLog()
public final Log getLog(Class<?> clazz)
class, if any.
If clazz is null, the default log is used. If
clazz is an anonymous class, the first non-anonymous
super class is used or the first and only
interface implemented (recursively as well).
clazz - The class; can be null, i.e. default log.
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||