aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/pom.xml12
-rw-r--r--common/src/main/java/at/gv/egovernment/moa/logging/Logger.java40
2 files changed, 34 insertions, 18 deletions
diff --git a/common/pom.xml b/common/pom.xml
index 72cf702bc..8f18a1b92 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -67,28 +67,24 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
- <version>2.7</version>
+ <version>${jodatime.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
- <version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
- <version>1.7.10</version>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.10</version>
- </dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
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);
}
/**