Author: rareddy
Date: 2009-08-12 12:36:33 -0400 (Wed, 12 Aug 2009)
New Revision: 1234
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/log/LogManager.java
trunk/common-internal/src/test/java/com/metamatrix/common/log/TestLogManager.java
Log:
TEIID-770
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/log/LogManager.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/log/LogManager.java 2009-08-11
03:25:47 UTC (rev 1233)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/log/LogManager.java 2009-08-12
16:36:33 UTC (rev 1234)
@@ -109,7 +109,7 @@
* not logged if this parameter is null
*/
public static void logCritical(String context, String message) {
- logListener.log(MessageLevel.CRITICAL, context, message);
+ logMessage(MessageLevel.CRITICAL, context, message);
}
/**
@@ -128,7 +128,7 @@
* @param message the log message (may be null)
*/
public static void logCritical(String context, Throwable e, String message) {
- logListener.log(MessageLevel.CRITICAL,context,e,message);
+ log(MessageLevel.CRITICAL,context,e,message);
}
/**
@@ -144,7 +144,7 @@
* not logged if this parameter is null
*/
public static void logError(String context, String message) {
- logListener.log(MessageLevel.ERROR, context,message);
+ logMessage(MessageLevel.ERROR, context,message);
}
/**
@@ -161,7 +161,7 @@
* @param message the log message (may be null)
*/
public static void logError(String context, Throwable e, String message) {
- logListener.log(MessageLevel.ERROR,context,e,message);
+ log(MessageLevel.ERROR,context,e,message);
}
/**
@@ -177,7 +177,7 @@
* not logged if this parameter is null
*/
public static void logWarning(String context, String message) {
- logListener.log(MessageLevel.WARNING, context,message);
+ logMessage(MessageLevel.WARNING, context,message);
}
/**
@@ -194,7 +194,7 @@
* @param message the log message (may be null)
*/
public static void logWarning(String context, Throwable e, String message) {
- logListener.log(MessageLevel.WARNING,context,e,message);
+ log(MessageLevel.WARNING,context,e,message);
}
/**
@@ -211,7 +211,7 @@
* not logged if this parameter is null
*/
public static void logInfo(String context, String message) {
- logListener.log(MessageLevel.INFO, context,message);
+ logMessage(MessageLevel.INFO, context,message);
}
/**
@@ -244,7 +244,7 @@
* @param message the log message (may be null)
*/
public static void logDetail(String context, Throwable e, String message) {
- logListener.log(MessageLevel.DETAIL,context,e,message);
+ log(MessageLevel.DETAIL,context,e,message);
}
/**
@@ -294,7 +294,7 @@
* not logged if this parameter is null
*/
public static void log(int msgLevel, String context, Object message) {
- logListener.log(msgLevel, context, message);
+ logMessage(msgLevel, context, message);
}
/**
@@ -310,6 +310,9 @@
* not logged if this parameter is null
*/
public static void log(int msgLevel, String context, Throwable e, Object message) {
+ if (!isMessageToBeRecorded(context, msgLevel)) {
+ return;
+ }
logListener.log(msgLevel, context, e, message);
}
Modified:
trunk/common-internal/src/test/java/com/metamatrix/common/log/TestLogManager.java
===================================================================
---
trunk/common-internal/src/test/java/com/metamatrix/common/log/TestLogManager.java 2009-08-11
03:25:47 UTC (rev 1233)
+++
trunk/common-internal/src/test/java/com/metamatrix/common/log/TestLogManager.java 2009-08-12
16:36:33 UTC (rev 1234)
@@ -98,16 +98,57 @@
}
List recevedMsgList = listener.getLoggedMessages();
+ assertEquals(sentMsgList.size(), recevedMsgList.size());
assertEquals(sentMsgList, recevedMsgList);
}
+
+ public void testFilterMessage() {
+ final LogConfiguration cfg = LogManager.getLogConfigurationCopy();
+ cfg.setLogLevel(context, MessageLevel.INFO );
+ LogManager.setLogConfiguration(cfg);
+
+ LogListener listener = new LogListener() {
+ @Override
+ public void log(int level, String context, Object msg) {
+ int setLevel = cfg.getLogLevel(context);
+ assertTrue(level <= setLevel);
+ }
+ @Override
+ public void log(int level, String context, Throwable t, Object msg) {
+ int setLevel = cfg.getLogLevel(context);
+ assertTrue(level <= setLevel);
+ }
+
+ @Override
+ public void shutdown() {
+ }
+ };
+ LogManager.logListener = listener;
+
+ LogManager.logCritical(context, "message"); //$NON-NLS-1$
+ LogManager.logDetail(context, "msgParts");//$NON-NLS-1$
+ LogManager.logError(context, "message");//$NON-NLS-1$
+ LogManager.logInfo(context, "message");//$NON-NLS-1$
+ LogManager.logTrace(context, "msgParts");//$NON-NLS-1$
+ LogManager.logWarning(context, "message");//$NON-NLS-1$
+
+ Exception e = new Exception("test"); //$NON-NLS-1$
+ LogManager.logCritical(context, e, "message"); //$NON-NLS-1$
+ LogManager.logDetail(context, e, "msgParts");//$NON-NLS-1$
+ LogManager.logError(context, e, "message");//$NON-NLS-1$
+ LogManager.log(MessageLevel.INFO, context, e, "message");//$NON-NLS-1$
+ LogManager.logTrace(context,e, "msgParts");//$NON-NLS-1$
+ LogManager.logWarning(context, e, "message");//$NON-NLS-1$
+ }
+
/**
*
* A log listener that saves messages (IStatus)s in a
* List for later comparison.
*/
class ListLogger implements LogListener {
- private List messages = new ArrayList();
+ private List<String> messages = new ArrayList<String>();
private int expectedMessages;
public ListLogger(int expectedMessages) {
@@ -118,14 +159,14 @@
* @see
com.metamatrix.core.log.LogListener#logMessage(org.eclipse.core.runtime.IStatus, long,
java.lang.String, java.lang.String)
*/
public synchronized void log(int level, String context, Object msg){
- this.messages.add(msg);
+ this.messages.add(msg.toString());
if (this.messages.size() == expectedMessages) {
this.notifyAll();
}
}
public void log(int level, String context, Throwable t, Object msg) {
- this.messages.add(msg);
+ this.messages.add(msg.toString());
if (this.messages.size() == expectedMessages) {
this.notifyAll();
}
@@ -153,6 +194,4 @@
}
-
-
}