You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/08/30 05:43:05 UTC
[3/3] git commit: Add log warnings for problems with lookups.
Add log warnings for problems with lookups.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b40793c2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b40793c2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b40793c2
Branch: refs/heads/master
Commit: b40793c2f92073699a0235052ae357e752ab6bd8
Parents: c14ac21
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Aug 29 22:42:50 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Aug 29 22:42:50 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/core/lookup/DateLookup.java | 6 +++++-
.../logging/log4j/core/lookup/JndiLookup.java | 14 +++++++++++---
.../log4j/core/lookup/ResourceBundleLookup.java | 20 +++++++++++++-------
.../core/lookup/SystemPropertiesLookup.java | 16 +++++++++-------
4 files changed, 38 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b40793c2/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/DateLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/DateLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/DateLookup.java
index 60eeb77..3ea529d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/DateLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/DateLookup.java
@@ -21,6 +21,8 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.status.StatusLogger;
@@ -32,6 +34,8 @@ import org.apache.logging.log4j.status.StatusLogger;
public class DateLookup implements StrLookup {
private static final Logger LOGGER = StatusLogger.getLogger();
+ private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP");
+
/**
* Looks up the value of the environment variable.
* @param key the format to use. If null, the default DateFormat will be used.
@@ -59,7 +63,7 @@ public class DateLookup implements StrLookup {
try {
dateFormat = new SimpleDateFormat(format);
} catch (final Exception ex) {
- LOGGER.error("Invalid date format: \"" + format + "\", using default", ex);
+ LOGGER.error(LOOKUP, "Invalid date format: [{}], using default", format, ex);
}
}
if (dateFormat == null) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b40793c2/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
index 25439cd..813230c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
@@ -20,9 +20,13 @@ import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.util.JndiCloser;
+import org.apache.logging.log4j.status.StatusLogger;
/**
* Looks up keys from JNDI resources.
@@ -30,7 +34,10 @@ import org.apache.logging.log4j.core.util.JndiCloser;
@Plugin(name = "jndi", category = "Lookup")
public class JndiLookup implements StrLookup {
- /** JNDI resourcce path prefix used in a J2EE container */
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP");
+
+ /** JNDI resource path prefix used in a J2EE container */
static final String CONTAINER_JNDI_RESOURCE_PATH_PREFIX = "java:comp/env/";
/**
@@ -54,12 +61,13 @@ public class JndiLookup implements StrLookup {
if (key == null) {
return null;
}
-
+ final String jndiName = convertJndiName(key);
Context ctx = null;
try {
ctx = new InitialContext();
- return (String) ctx.lookup(convertJndiName(key));
+ return (String) ctx.lookup(jndiName);
} catch (final NamingException e) {
+ LOGGER.warn(LOOKUP, "Error looking up JNDI resource [{}].", jndiName, e);
return null;
} finally {
JndiCloser.closeSilently(ctx);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b40793c2/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
index d1a2da6..07bf419 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
@@ -19,8 +19,12 @@ package org.apache.logging.log4j.core.lookup;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.status.StatusLogger;
/**
* Looks up keys from resource bundles.
@@ -28,11 +32,14 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
@Plugin(name = "bundle", category = "Lookup")
public class ResourceBundleLookup implements StrLookup {
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP");
+
/**
* Looks up the value for the key in the format "BundleName:BundleKey".
- *
+ *
* For example: "com.domain.messages:MyKey".
- *
+ *
* @param key
* the key to be looked up, may be null
* @return The value for the key.
@@ -45,8 +52,7 @@ public class ResourceBundleLookup implements StrLookup {
final String[] keys = key.split(":");
final int keyLen = keys.length;
if (keyLen != 2) {
- // throw new IllegalArgumentException("Bad key format " + key + ", format is BundleName:Value");
- // log?
+ LOGGER.warn(LOOKUP, "Bad ResourceBundle key format [{}]. Expected format is BundleName:KeyName.", key);
return null;
}
final String bundleName = keys[0];
@@ -55,16 +61,16 @@ public class ResourceBundleLookup implements StrLookup {
// The ResourceBundle class caches bundles, no need to cache here.
return ResourceBundle.getBundle(bundleName).getString(bundleKey);
} catch (final MissingResourceException e) {
- // log?
+ LOGGER.warn(LOOKUP, "Error looking up ResourceBundle [{}].", bundleName, e);
return null;
}
}
/**
* Looks up the value for the key in the format "BundleName:BundleKey".
- *
+ *
* For example: "com.domain.messages:MyKey".
- *
+ *
* @param event
* The current LogEvent.
* @param key
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b40793c2/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
index 00546a0..575a3dd 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
@@ -16,8 +16,12 @@
*/
package org.apache.logging.log4j.core.lookup;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.status.StatusLogger;
/**
* Looks up keys from system properties.
@@ -25,6 +29,9 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
@Plugin(name = "sys", category = "Lookup")
public class SystemPropertiesLookup implements StrLookup {
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP");
+
/**
* Looks up the value for the key.
* @param key the key to be looked up, may be null
@@ -35,7 +42,7 @@ public class SystemPropertiesLookup implements StrLookup {
try {
return System.getProperty(key);
} catch (final Exception ex) {
- // Should this be logged?
+ LOGGER.warn(LOOKUP, "Error while getting system property [{}].", key, ex);
return null;
}
}
@@ -48,11 +55,6 @@ public class SystemPropertiesLookup implements StrLookup {
*/
@Override
public String lookup(final LogEvent event, final String key) {
- try {
- return System.getProperty(key);
- } catch (final Exception ex) {
- // Should this be logged?
- return null;
- }
+ return lookup(key);
}
}