aboutsummaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorFlorian Reimair <florian.reimair@iaik.tugraz.at>2015-03-10 14:35:12 +0100
committerFlorian Reimair <florian.reimair@iaik.tugraz.at>2015-03-10 14:35:12 +0100
commit414152df1310067623f10f90cfb89293926dd681 (patch)
tree65b8a001ac4a0c741af2b9fe4ffed7f8b6182132 /common/src
parentaa6bb4186317b8f4c9a2c6bdb71d774ee69173c5 (diff)
downloadmoa-id-spss-414152df1310067623f10f90cfb89293926dd681.tar.gz
moa-id-spss-414152df1310067623f10f90cfb89293926dd681.tar.bz2
moa-id-spss-414152df1310067623f10f90cfb89293926dd681.zip
save some ram with logger
Diffstat (limited to 'common/src')
-rw-r--r--common/src/main/java/at/gv/egovernment/moa/logging/Logger.java52
1 files changed, 39 insertions, 13 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 2e76325a5..184be20cb 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
@@ -24,6 +24,9 @@
package at.gv.egovernment.moa.logging;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* A utility class acting as a facade to the logging subsystem.
*
@@ -45,6 +48,29 @@ public class Logger {
// there is no need for that anymore
}
+
+ /** The Constant instances. */
+ private static final Map<String, org.apache.log4j.Logger> instances = new HashMap<String, org.apache.log4j.Logger>();
+
+ /**
+ * Gets the logger.
+ *
+ * @return the logger
+ */
+ private static synchronized org.apache.log4j.Logger getLogger() {
+ String className = Thread.currentThread().getStackTrace()[3].getClassName();
+
+ org.apache.log4j.Logger logger = instances.get(className);
+ if (logger != null) {
+ return logger;
+ }
+
+ logger = org.apache.log4j.Logger.getLogger(className);
+ instances.put(className, logger);
+
+ return logger;
+ }
+
/**
* Test, if the trace log level is enabled.
*
@@ -52,7 +78,7 @@ public class Logger {
* <code>false</code> otherwise.
*/
public static boolean isTraceEnabled() {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
return logger.isTraceEnabled();
}
@@ -64,7 +90,7 @@ public class Logger {
* <code>false</code> otherwise.
*/
public static boolean isTraceEnabled(String hierarchy) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
return logger.isTraceEnabled();
}
@@ -74,7 +100,7 @@ public class Logger {
* @param message The message to trace.
*/
public static void trace(Object message) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.trace(message);
}
@@ -85,7 +111,7 @@ public class Logger {
* <code>false</code> otherwise.
*/
public static boolean isDebugEnabled() {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
return logger.isDebugEnabled();
}
@@ -97,7 +123,7 @@ public class Logger {
* <code>false</code> otherwise.
*/
public static boolean isDebugEnabled(String hierarchy) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
return logger.isDebugEnabled();
}
@@ -107,7 +133,7 @@ public class Logger {
* @param message The message to log.
*/
public static void debug(Object message) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.debug(message);
}
@@ -117,7 +143,7 @@ public class Logger {
* @param message The message to log.
*/
public static void info(Object message) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.info(message);
}
@@ -127,7 +153,7 @@ public class Logger {
* @param message The message to log.
*/
public static void warn(Object message) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.warn(message);
}
@@ -138,7 +164,7 @@ public class Logger {
* @param t An exception that may be the cause of the warning.
*/
public static void warn(Object message, Throwable t) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.warn(message, t);
}
@@ -148,7 +174,7 @@ public class Logger {
* @param message The message to log.
*/
public static void error(Object message) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.error(message);
}
@@ -159,7 +185,7 @@ public class Logger {
* @param t An exception that may be the cause of the error.
*/
public static void error(Object message, Throwable t) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.error(message, t);
}
@@ -169,7 +195,7 @@ public class Logger {
* @param message The message to log.
*/
public static void fatal(Object message) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.fatal(message);
}
@@ -180,7 +206,7 @@ public class Logger {
* @param t An exception that may be the cause of the error.
*/
public static void fatal(Object message, Throwable t) {
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Thread.currentThread().getStackTrace()[2].getClassName());
+ org.apache.log4j.Logger logger = getLogger();
logger.fatal(message, t);
}
}