Decoubled Logging
The main idea behind this 100000th iteration of the decoupled logging-mechanism is, that i did not want to:
-
rely on an framework
-
dont enforce the deveolper, to include any framework, they maybe don’t want to use.
Logging is decoupled at this framework, so that you can either use the given Instances or easyli create your own ones.
Logging provides serveral methods for logging, which are used to logg anthing inside NetCom2. It is orriented at Log4J. It has the levels:
-
trace
-
debug
-
info
-
warn
-
error
-
fatal
which are used as i just named them. Nearly everry little step is logged using trace, major parts with debug s.o.s.f.
The Logging interface is reduced to its needed methods, reducing the implementations to 9 methods to implement. Most likely, this will not be enough for your needs, therefor it is wise, to encapsulate your own logging framework into NetCom2.
Let’s say, you wanted to use Log4J as the Logging-framework of you choice and also use it for NetCom2. You would write something like this:
class Log4JLogging implements Logging {
private final Logger logger;
public Log4JLogging(Logger logger) {
this.logger = logger;
}
@Override
public void trace(Object s) {
logger.trace(s);
}
@Override
public void debug(Object s) {
logger.debug(s);
}
...
}
With that little class implemented, you have to Tell NetCom2 to use it. You can either:
If you are dealing with an class, that implements the Loggable interface (like the ClientStart or the ServerStart) you can tell them to use your Logging-class by stating:
serverStart.setLogging(new Log4JLogging());
The advantage is, that you can change some critical classes to logg differently than other classes.
The disadvantage is, that you most likely will only be able to state this, if a (in)significant part has been logged.
To change the behavior of all Classes inside NetCom2 (and maybe inside your code, if you use <code>Logging.unified()</code>) to use your Logging-instance by stating:
NetComLogging.setLogging(new Log4JLogging());
The advantage is, that you can change the Logging, before the first lines are logged.
Introduction
Advanced
Outdated
Further Reading
Versions explained
Examples