Author: rgoers
Date: Sun Jan 26 22:35:25 2014
New Revision: 1561564
URL: http://svn.apache.org/r1561564
Log:
Changes to custom Level support based on feedback
Added:
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/StandardLevel.java
Modified:
logging/log4j/log4j2/trunk/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Level.java
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/package-info.java
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java
logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java
Modified:
logging/log4j/log4j2/trunk/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java?rev=1561564&r1=1561563&r2=1561564&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
Sun Jan 26 22:35:25 2014
@@ -31,7 +31,6 @@ import org.apache.logging.log4j.core.hel
import org.apache.logging.log4j.message.LocalizedMessage;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.ObjectMessage;
-import org.apache.logging.log4j.Level.StdLevel;
/**
@@ -156,12 +155,7 @@ public class Category {
}
public final Level getEffectiveLevel() {
- final org.apache.logging.log4j.Level level = logger.getLevel();
- return getEffectiveLevel(StdLevel.getStdLevel(level));
- }
-
- private Level getEffectiveLevel(StdLevel level) {
- switch (level) {
+ switch (logger.getLevel().getStandardLevel()) {
case TRACE:
return Level.TRACE;
case DEBUG:
Modified:
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Level.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Level.java?rev=1561564&r1=1561563&r2=1561564&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Level.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/Level.java
Sun Jan 26 22:35:25 2014
@@ -16,108 +16,86 @@
*/
package org.apache.logging.log4j;
+import org.apache.logging.log4j.spi.StandardLevel;
+
import java.io.ObjectStreamException;
import java.io.Serializable;
-import java.util.EnumSet;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-public class Level implements Comparable<Level>, Serializable {
+/**
+ * Levels used for identifying the severity of an event. Levels are organized
from most specific to least:
+ * <ul>
+ * <li>{@link #OFF} (most specific)</li>
+ * <li>{@link #FATAL}</li>
+ * <li>{@link #ERROR}</li>
+ * <li>{@link #WARN}</li>
+ * <li>{@link #INFO}</li>
+ * <li>{@link #DEBUG}</li>
+ * <li>{@link #TRACE}</li>
+ * <li>{@link #ALL} (least specific)</li>
+ * </ul>
+ *
+ * Typically, configuring a level in a filter or on a logger will cause
logging events of that level and those
+ * that are more specific to pass through the filter.
+ * A special level, {@link #ALL}, is guaranteed to capture all levels when
used in logging configurations.
+ */
+public abstract class Level implements Comparable<Level>, Serializable {
private static final long serialVersionUID = 3077535362528045615L;
- private static ConcurrentMap<String, Level> levels = new
ConcurrentHashMap<String, Level>();
- private static Object constructorLock = new Object();
+ private static final ConcurrentMap<String, Level> levels = new
ConcurrentHashMap<String, Level>();
+ private static final Object constructorLock = new Object();
private static int ordinalCount = 0;
- public static Level OFF = new Level("OFF", 0){};
- public static Level FATAL = new Level("FATAL", 100);
- public static Level ERROR = new Level("ERROR", 200);
- public static Level WARN = new Level("WARN", 300);
- public static Level INFO = new Level("INFO", 400);
- public static Level DEBUG = new Level("DEBUG", 500);
- public static Level TRACE = new Level("TRACE", 600);
- public static Level ALL = new Level("ALL", Integer.MAX_VALUE);
-
- public enum StdLevel {
-
- /**
- * No events will be logged.
- */
- OFF(Level.OFF.intLevel()),
-
- /**
- * A severe error that will prevent the application from continuing.
- */
- FATAL(Level.FATAL.intLevel()),
-
- /**
- * An error in the application, possibly recoverable.
- */
- ERROR(Level.ERROR.intLevel()),
-
- /**
- * An event that might possible lead to an error.
- */
- WARN(Level.WARN.intLevel()),
-
- /**
- * An event for informational purposes.
- */
- INFO(Level.INFO.intLevel()),
-
- /**
- * A general debugging event.
- */
- DEBUG(Level.DEBUG.intLevel()),
-
- /**
- * A fine-grained debug message, typically capturing the flow through
the application.
- */
- TRACE(Level.TRACE.intLevel()),
-
- /**
- * All events should be logged.
- */
- ALL(Level.ALL.intLevel());
-
-
- private final int intLevel;
-
- private static final EnumSet<StdLevel> levelSet =
EnumSet.allOf(StdLevel.class);
-
- private StdLevel(final int val) {
- intLevel = val;
- }
-
- /**
- * Returns the integer value of the Level.
- * @return the integer value of the Level.
- */
- public int intLevel() {
- return intLevel;
- }
+ /**
+ * No events will be logged.
+ */
+ public static Level OFF;
+ /**
+ * A severe error that will prevent the application from continuing.
+ */
+ public static Level FATAL;
+ /**
+ * An error in the application, possibly recoverable.
+ */
+ public static Level ERROR;
+ /**
+ * An event that might possible lead to an error.
+ */
+ public static Level WARN;
+ /**
+ * An event for informational purposes.
+ */
+ public static Level INFO;
+ /**
+ * A general debugging event.
+ */
+ public static Level DEBUG;
+ /**
+ * A fine-grained debug message, typically capturing the flow through the
application.
+ */
+ public static Level TRACE;
+ /**
+ * All events should be logged.
+ */
+ public static Level ALL;
- /**
- * Method to convert custom Levels into a StdLevel for conversion to
other systems.
- * @param level The Level.
- * @return The StdLevel.
- */
- public static StdLevel getStdLevel(Level level) {
- StdLevel severityLevel = StdLevel.OFF;
- for (StdLevel lvl : levelSet) {
- if (lvl.intLevel() > level.intLevel()) {
- break;
- }
- severityLevel = lvl;
- }
- return severityLevel;
- }
+ static {
+ OFF = new Level("OFF", StandardLevel.OFF.intLevel()){};
+ FATAL = new Level("FATAL", StandardLevel.FATAL.intLevel()){};
+ ERROR = new Level("ERROR", StandardLevel.ERROR.intLevel()){};
+ WARN = new Level("WARN", StandardLevel.WARN.intLevel()){};
+ INFO = new Level("INFO", StandardLevel.INFO.intLevel()){};
+ DEBUG = new Level("DEBUG", StandardLevel.DEBUG.intLevel()){};
+ TRACE = new Level("TRACE", StandardLevel.TRACE.intLevel()){};
+ ALL = new Level("ALL", StandardLevel.ALL.intLevel()){};
}
private final String name;
private final int intLevel;
private final int ordinal;
+ private final StandardLevel standardLevel;
protected Level(String name, int intLevel) {
if (name == null || name.length() == 0) {
@@ -128,13 +106,10 @@ public class Level implements Comparable
}
this.name = name;
this.intLevel = intLevel;
+ this.standardLevel = StandardLevel.getStandardLevel(intLevel);
synchronized(constructorLock) {
if (levels.containsKey(name)) {
- Level level = levels.get(name);
- if (level.intLevel() != intLevel) {
- throw new IllegalArgumentException("Level " + name + " has
already been defined.");
- }
- ordinal = level.ordinal;
+ throw new IllegalArgumentException("Level " + name + " has
already been defined.");
} else {
ordinal = ordinalCount++;
levels.put(name, this);
@@ -142,14 +117,18 @@ public class Level implements Comparable
}
}
- public int intLevel() {
+ public final int intLevel() {
return this.intLevel;
}
- public int ordinal() {
+ public final int ordinal() {
return this.ordinal;
}
+ public final StandardLevel getStandardLevel() {
+ return standardLevel;
+ }
+
/**
* Compares this level against the level passed as an argument and returns
true if this
* level is the same or more specific.
@@ -157,7 +136,7 @@ public class Level implements Comparable
* @param level The level to check.
* @return True if the passed Level is more specific or the same as this
Level.
*/
- public boolean isAtLeastAsSpecificAs(final Level level) {
+ public final boolean isAtLeastAsSpecificAs(final Level level) {
return this.intLevel <= level.intLevel;
}
@@ -168,7 +147,7 @@ public class Level implements Comparable
* @param level The level to check.
* @return True if the passed Level is more specific or the same as this
Level.
*/
- public boolean isAtLeastAsSpecificAs(final int level) {
+ public final boolean isAtLeastAsSpecificAs(final int level) {
return this.intLevel <= level;
}
@@ -177,7 +156,7 @@ public class Level implements Comparable
* @param level The level to check.
* @return True if the passed Level is more specific or the same as this
Level.
*/
- public boolean lessOrEqual(final Level level) {
+ public final boolean lessOrEqual(final Level level) {
return this.intLevel <= level.intLevel;
}
@@ -186,42 +165,42 @@ public class Level implements Comparable
* @param level The level to check.
* @return True if the passed Level is more specific or the same as this
Level.
*/
- public boolean lessOrEqual(final int level) {
+ public final boolean lessOrEqual(final int level) {
return this.intLevel <= level;
}
@Override
@SuppressWarnings("CloneDoesntCallSuperClone")
- public Level clone() throws CloneNotSupportedException {
+ public final Level clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
@Override
- public int compareTo(Level other) {
+ public final int compareTo(Level other) {
return intLevel < other.intLevel ? -1 : (intLevel > other.intLevel ? 1
: 0);
}
@Override
- public boolean equals(Object other) {
+ public final boolean equals(Object other) {
return other instanceof Level && other == this;
}
- public Class<Level> getDeclaringClass() {
+ public final Class<Level> getDeclaringClass() {
return Level.class;
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return this.name.hashCode();
}
- public String name() {
+ public final String name() {
return this.name;
}
@Override
- public String toString() {
+ public final String toString() {
return this.name;
}
Added:
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/StandardLevel.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/StandardLevel.java?rev=1561564&view=auto
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/StandardLevel.java
(added)
+++
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/StandardLevel.java
Sun Jan 26 22:35:25 2014
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.spi;
+
+import java.util.EnumSet;
+
+/**
+ * Standard Logging Levels as an enumeration for use internally. This enum is
used as a parameter in
+ * any public APIs.
+ */
+public enum StandardLevel {
+
+ /**
+ * No events will be logged.
+ */
+ OFF(0),
+
+ /**
+ * A severe error that will prevent the application from continuing.
+ */
+ FATAL(100),
+
+ /**
+ * An error in the application, possibly recoverable.
+ */
+ ERROR(200),
+
+ /**
+ * An event that might possible lead to an error.
+ */
+ WARN(300),
+
+ /**
+ * An event for informational purposes.
+ */
+ INFO(400),
+
+ /**
+ * A general debugging event.
+ */
+ DEBUG(500),
+
+ /**
+ * A fine-grained debug message, typically capturing the flow through the
application.
+ */
+ TRACE(600),
+
+ /**
+ * All events should be logged.
+ */
+ ALL(Integer.MAX_VALUE);
+
+
+ private final int intLevel;
+
+ private static final EnumSet<StandardLevel> levelSet =
EnumSet.allOf(StandardLevel.class);
+
+ private StandardLevel(final int val) {
+ intLevel = val;
+ }
+
+ /**
+ * Returns the integer value of the Level.
+ * @return the integer value of the Level.
+ */
+ public int intLevel() {
+ return intLevel;
+ }
+
+ /**
+ * Method to convert custom Levels into a StdLevel for conversion to other
systems.
+ * @param intLevel The integer value of the Level.
+ * @return The StdLevel.
+ */
+ public static StandardLevel getStandardLevel(int intLevel) {
+ StandardLevel level = StandardLevel.OFF;
+ for (StandardLevel lvl : levelSet) {
+ if (lvl.intLevel() > intLevel) {
+ break;
+ }
+ level = lvl;
+ }
+ return level;
+ }
+}
Modified:
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/package-info.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/package-info.java?rev=1561564&r1=1561563&r2=1561564&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/package-info.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/spi/package-info.java
Sun Jan 26 22:35:25 2014
@@ -15,6 +15,7 @@
* limitations under the license.
*/
/**
- * Internal interfaces and classes to be used by authors of logging
implementations.
+ * Internal interfaces and classes to be used by authors of logging
implementations or for internal use by
+ * API classes.
*/
package org.apache.logging.log4j.spi;
Modified:
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java?rev=1561564&r1=1561563&r2=1561564&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Sun Jan 26 22:35:25 2014
@@ -251,7 +251,7 @@ public final class StatusLogger extends
return listenersLevel >= level.intLevel();
}
- switch (Level.StdLevel.getStdLevel(level)) {
+ switch (level.getStandardLevel()) {
case FATAL:
return logger.isFatalEnabled(marker);
case TRACE:
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java?rev=1561564&r1=1561563&r2=1561564&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/Severity.java
Sun Jan 26 22:35:25 2014
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.core.net;
import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.spi.StandardLevel;
import java.util.EnumSet;
@@ -82,11 +83,7 @@ public enum Severity {
* @return The matching Severity, or DEBUG if there is no match.
*/
public static Severity getSeverity(final Level level) {
- return getSeverity(Level.StdLevel.getStdLevel(level));
- }
-
- private static Severity getSeverity(final Level.StdLevel level) {
- switch (level) {
+ switch (level.getStandardLevel()) {
case ALL:
return DEBUG;
case TRACE:
Modified:
logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java?rev=1561564&r1=1561563&r2=1561564&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/SLF4JLogger.java
Sun Jan 26 22:35:25 2014
@@ -18,7 +18,6 @@ package org.apache.logging.slf4j;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
-import org.apache.logging.log4j.Level.StdLevel;
import org.apache.logging.log4j.message.LoggerNameAwareMessage;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.MessageFactory;
@@ -57,7 +56,7 @@ public class SLF4JLogger extends Abstrac
locationAwareLogger.log(getMarker(marker), fqcn,
convertLevel(level), data.getFormattedMessage(),
data.getParameters(), t);
} else {
- switch (StdLevel.getStdLevel(level)) {
+ switch (level.getStandardLevel()) {
case DEBUG :
logger.debug(getMarker(marker),
data.getFormattedMessage(), data.getParameters(), t);
break;
@@ -94,7 +93,7 @@ public class SLF4JLogger extends Abstrac
}
private int convertLevel(final Level level) {
- switch (StdLevel.getStdLevel(level)) {
+ switch (level.getStandardLevel()) {
case DEBUG :
return LocationAwareLogger.DEBUG_INT;
case TRACE :
@@ -137,7 +136,7 @@ public class SLF4JLogger extends Abstrac
private boolean isEnabledFor(final Level level, final Marker marker) {
final org.slf4j.Marker slf4jMarker = getMarker(marker);
- switch (StdLevel.getStdLevel(level)) {
+ switch (level.getStandardLevel()) {
case DEBUG :
return logger.isDebugEnabled(slf4jMarker);
case TRACE :