aboutsummaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorBojan Suzic <bojan.suzic@iaik.tugraz.at>2015-05-11 13:35:06 +0200
committerBojan Suzic <bojan.suzic@iaik.tugraz.at>2015-05-11 13:35:06 +0200
commit6501da184914a797babb2a2a49eb0d88fd6aacbc (patch)
tree052d04159768f3a63fd0718e45fa43c6f8b9bf09 /common/src
parent5830752a2142b9664bc46196c1a67250cbedf655 (diff)
parentc230145208b7fbe53b7bf2d6aff49a24301559eb (diff)
downloadmoa-id-spss-6501da184914a797babb2a2a49eb0d88fd6aacbc.tar.gz
moa-id-spss-6501da184914a797babb2a2a49eb0d88fd6aacbc.tar.bz2
moa-id-spss-6501da184914a797babb2a2a49eb0d88fd6aacbc.zip
Merge branch '2.2.x-Snapshot' of gitlab.iaik.tugraz.at:afitzek/moa-idspss into 2.2.x-Snapshot
Diffstat (limited to 'common/src')
-rw-r--r--common/src/main/java/at/gv/egovernment/moa/logging/Logger.java40
1 files changed, 30 insertions, 10 deletions
diff --git a/common/src/main/java/at/gv/egovernment/moa/logging/Logger.java b/common/src/main/java/at/gv/egovernment/moa/logging/Logger.java
index 6999656ab..7cb2e7daf 100644
--- a/common/src/main/java/at/gv/egovernment/moa/logging/Logger.java
+++ b/common/src/main/java/at/gv/egovernment/moa/logging/Logger.java
@@ -58,7 +58,14 @@ public class Logger {
* @return the logger
*/
private static synchronized org.slf4j.Logger getLogger() {
- String className = Thread.currentThread().getStackTrace()[3].getClassName();
+ StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
+
+ int i;
+ for(i = 2; i < stacktrace.length; i++)
+ if(!stacktrace[i].getClassName().equals(Logger.class.getName()))
+ break;
+
+ String className = stacktrace[i].getClassName();
org.slf4j.Logger logger = instances.get(className);
if (logger != null) {
@@ -72,6 +79,19 @@ public class Logger {
}
/**
+ * Prepare the message for printing it as string.
+ * <p>Mainly introduce because the <code>message</code> might be <code>null</code>.
+ *
+ * @param message the message
+ * @return the string
+ */
+ private static String prepareMessage(Object message) {
+ if(null == message)
+ return "no message given";
+ return message.toString();
+ }
+
+ /**
* Test, if the trace log level is enabled.
*
* @return boolean <code>true</code>, if tracing output is enabled
@@ -101,7 +121,7 @@ public class Logger {
*/
public static void trace(Object message) {
org.slf4j.Logger logger = getLogger();
- logger.trace(message.toString());
+ logger.trace(prepareMessage(message));
}
/**
@@ -134,17 +154,17 @@ public class Logger {
*/
public static void debug(Object message) {
org.slf4j.Logger logger = getLogger();
- logger.debug(message.toString());
+ logger.debug(prepareMessage(message));
}
-
- /**
+
+/**
* Log an info message.
*
* @param message The message to log.
*/
public static void info(Object message) {
org.slf4j.Logger logger = getLogger();
- logger.info(message.toString());
+ logger.info(prepareMessage(message));
}
/**
@@ -154,7 +174,7 @@ public class Logger {
*/
public static void warn(Object message) {
org.slf4j.Logger logger = getLogger();
- logger.warn(message.toString());
+ logger.warn(prepareMessage(message));
}
/**
@@ -165,7 +185,7 @@ public class Logger {
*/
public static void warn(Object message, Throwable t) {
org.slf4j.Logger logger = getLogger();
- logger.warn(message.toString(), t);
+ logger.warn(prepareMessage(message), t);
}
/**
@@ -175,7 +195,7 @@ public class Logger {
*/
public static void error(Object message) {
org.slf4j.Logger logger = getLogger();
- logger.error(message.toString());
+ logger.error(prepareMessage(message));
}
/**
@@ -186,7 +206,7 @@ public class Logger {
*/
public static void error(Object message, Throwable t) {
org.slf4j.Logger logger = getLogger();
- logger.error(message.toString(), t);
+ logger.error(prepareMessage(message), t);
}
/**