Skip to content

Preinstalled Logging

Thorben Kuck edited this page Oct 15, 2017 · 18 revisions

NetCom2 Comes with several preinstalled Logging-implementations. Each of those implementations is reachable by stating: Logging.[...] whilst Logging is the com.github.thorbenkuck.netcom2.network.interfaces Interface. Those are:

Logging.trace() Logging.trace() will print out every little bit of what should be logged. The Logging of an unsuccessful clientstart using this code:
NetComLogging.setLogging(Logging.disabled());
ClientStart clientStart = ClientStart.at(address, port);
NetComLogging.setLogging(Logging.trace());
clientStart.launch();

looks like this:

[2017-10-15T15:44:30.597] (Thread[main,5,main]) DEBUG : Connecting to server ..
[2017-10-15T15:44:30.602] (Thread[main,5,main]) TRACE : Trying to establish Connection ..
[2017-10-15T15:44:30.602] (Thread[main,5,main]) DEBUG : Trying to establish connection to :0
[2017-10-15T15:44:30.602] (Thread[main,5,main]) TRACE : Creating Socket by SocketFactory ..
com.github.thorbenkuck.netcom2.exceptions.StartFailedException: java.io.IOException:java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)
Logging.callerTrace() Logging.callerTrace() is simmiliar to Logging.trace(). It prints out every depth of the Logging framework.

HOWEVER

This implemenation prints out, which method triggered the logged message. So if you state:

NetComLogging.setLogging(Logging.callerTrace());
ClientStart.launch(); 

the output will look like Logging.trace() with the addition that you can see the exact Class, which called it. This looks a little something like this:

[2017-10-15T16:12:23.084] (Thread[main,5,main]) [com.github.thorbenkuck.netcom2.network.client.ClientStartImpl] DEBUG : Connecting to server ..
[2017-10-15T16:12:23.085] (Thread[main,5,main]) [com.github.thorbenkuck.netcom2.network.client.ClientStartImpl] TRACE : Trying to establish Connection ..
[2017-10-15T16:12:23.085] (Thread[main,5,main]) [com.github.thorbenkuck.netcom2.network.client.ClientConnector] DEBUG : Trying to establish connection to :0
[2017-10-15T16:12:23.085] (Thread[main,5,main]) [com.github.thorbenkuck.netcom2.network.client.ClientConnector] TRACE : Creating Socket by SocketFactory ..
com.github.thorbenkuck.netcom2.exceptions.StartFailedException: java.io.IOException: java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)

NOTE

This logging uses reflections to find out, which Class is calling it, so use it with care!

Logging.debug() Logging.debug() will behave as Logging.trace(), but ignoring .trace(String) calls. The Logging of an unsuccessful clientstart using this code:
NetComLogging.setLogging(Logging.disabled());
ClientStart clientStart = ClientStart.at(address, port);
NetComLogging.setLogging(Logging.debug());
clientStart.launch();

looks like this:

[2017-10-15T15:44:30.610] (Thread[main,5,main]) DEBUG : Connecting to server ..
[2017-10-15T15:44:30.610] (Thread[main,5,main]) DEBUG : Trying to establish connection to :0
com.github.thorbenkuck.netcom2.exceptions.StartFailedException: java.io.IOException: java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)
Logging.info() Logging.info() will behave as Logging.debug(), but ignoring .debug(String) calls. The Logging of an unsuccessful clientstart using this code:
NetComLogging.setLogging(Logging.disabled());
ClientStart clientStart = ClientStart.at(address, port);
NetComLogging.setLogging(Logging.info());
clientStart.launch();

looks like this:

com.github.thorbenkuck.netcom2.exceptions.StartFailedException: java.io.IOException: java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)
Logging.warn() Logging.warn() will behave as Logging.info(), but ignoring .info(String) calls. The Logging of an unsuccessful clientstart using this code:
NetComLogging.setLogging(Logging.disabled());
ClientStart clientStart = ClientStart.at(address, port);
NetComLogging.setLogging(Logging.info());
clientStart.launch();

looks like this:

com.github.thorbenkuck.netcom2.exceptions.StartFailedException: java.io.IOException: java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)
Logging.error() Logging.error() will behave as Logging.warn(), but ignoring .warn(String) calls. The Logging of an unsuccessful clientstart using this code:
NetComLogging.setLogging(Logging.disabled());
ClientStart clientStart = ClientStart.at(address, port);
NetComLogging.setLogging(Logging.info());
clientStart.launch();

looks like this:

com.github.thorbenkuck.netcom2.exceptions.StartFailedException: java.io.IOException: java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)

Every instance will at least log error and fatal calls. To disable those, you would have to write your own implementation.


For your convenience

The Logging interface also provides some other methods for some commen problems.

  • Logging.disabled() returns an instance, where every call is ignored and nothing is logged.
  • Logging.getDefault() returns the, for NetCom2 default logging instance, which currently is the .error().
  • Logging.unified() returns an globaly synchronized Logging instance. If you change the global instance by stating NetComLogging.setLogging(/Whatever/), this instance will also use this newly set instance.

Clone this wiki locally