You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by Matt Sicker <bo...@gmail.com> on 2017/06/30 14:42:59 UTC
Re: logging-log4j2 git commit: LOG4J2-1813 Log4j2 will now print all
internal logging to the console if system property `log4j2.debug` is defined
with any value (or no value).
This is great!
On 30 June 2017 at 09:27, <rp...@apache.org> wrote:
> Repository: logging-log4j2
> Updated Branches:
> refs/heads/master 9d049426a -> 785892d6a
>
>
> LOG4J2-1813 Log4j2 will now print all internal logging to the console if
> system property `log4j2.debug` is defined with any value (or no value).
>
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/
> commit/785892d6
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/785892d6
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/785892d6
>
> Branch: refs/heads/master
> Commit: 785892d6a5c89350e06d3bc802a86d8e75f29337
> Parents: 9d04942
> Author: rpopma <rp...@apache.org>
> Authored: Fri Jun 30 23:27:07 2017 +0900
> Committer: rpopma <rp...@apache.org>
> Committed: Fri Jun 30 23:27:07 2017 +0900
>
> ----------------------------------------------------------------------
> .../logging/log4j/status/StatusLogger.java | 27 +++++++++++++++-----
> .../apache/logging/log4j/util/Constants.java | 11 ++++++++
> .../logging/log4j/util/PropertiesUtil.java | 9 +++++++
> .../log4j/core/config/ConfigurationFactory.java | 4 +--
> src/changes/changes.xml | 3 +++
> src/site/markdown/faq.md.vm | 13 ++++++++--
> src/site/xdoc/manual/configuration.xml.vm | 20 +++++++++++++--
> 7 files changed, 75 insertions(+), 12 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 785892d6/log4j-api/src/main/java/org/apache/logging/log4j/
> status/StatusLogger.java
> ----------------------------------------------------------------------
> diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
> b/log4j-api/src/main/java/org/apache/logging/log4j/status/
> StatusLogger.java
> index 8e74a35..4fc26c1 100644
> --- a/log4j-api/src/main/java/org/apache/logging/log4j/status/
> StatusLogger.java
> +++ b/log4j-api/src/main/java/org/apache/logging/log4j/status/
> StatusLogger.java
> @@ -37,6 +37,7 @@ import org.apache.logging.log4j.message.
> ParameterizedNoReferenceMessageFactory;
> import org.apache.logging.log4j.simple.SimpleLogger;
> import org.apache.logging.log4j.simple.SimpleLoggerContext;
> import org.apache.logging.log4j.spi.AbstractLogger;
> +import org.apache.logging.log4j.util.Constants;
> import org.apache.logging.log4j.util.PropertiesUtil;
> import org.apache.logging.log4j.util.Strings;
>
> @@ -98,6 +99,11 @@ public final class StatusLogger extends AbstractLogger {
> this.logger = new SimpleLogger("StatusLogger", Level.ERROR,
> false, true, false, false, Strings.EMPTY,
> messageFactory, PROPS, System.err);
> this.listenersLevel = Level.toLevel(DEFAULT_STATUS_LEVEL,
> Level.WARN).intLevel();
> +
> + // LOG4J2-1813 if system property "log4j2.debug" is defined,
> print all status logging
> + if (PropertiesUtil.getProperties().hasProperty(Constants.LOG4J2_DEBUG))
> {
> + logger.setLevel(Level.TRACE);
> + }
> }
>
> /**
> @@ -248,14 +254,19 @@ public final class StatusLogger extends
> AbstractLogger {
> } finally {
> msgLock.unlock();
> }
> - if (listeners.size() > 0) {
> - for (final StatusListener listener : listeners) {
> - if (data.getLevel().isMoreSpecificThan(listener.getStatusLevel()))
> {
> - listener.log(data);
> + // LOG4J2-1813 if system property "log4j2.debug" is defined, all
> status logging is enabled
> + if (PropertiesUtil.getProperties().hasProperty(Constants.LOG4J2_DEBUG))
> {
> + logger.logMessage(fqcn, level, marker, msg, t);
> + } else {
> + if (listeners.size() > 0) {
> + for (final StatusListener listener : listeners) {
> + if (data.getLevel().isMoreSpecificThan(listener.getStatusLevel()))
> {
> + listener.log(data);
> + }
> }
> + } else {
> + logger.logMessage(fqcn, level, marker, msg, t);
> }
> - } else {
> - logger.logMessage(fqcn, level, marker, msg, t);
> }
> }
>
> @@ -378,6 +389,10 @@ public final class StatusLogger extends
> AbstractLogger {
>
> @Override
> public boolean isEnabled(final Level level, final Marker marker) {
> + // LOG4J2-1813 if system property "log4j2.debug" is defined, all
> status logging is enabled
> + if (PropertiesUtil.getProperties().hasProperty(Constants.LOG4J2_DEBUG))
> {
> + return true;
> + }
> if (listeners.size() > 0) {
> return listenersLevel >= level.intLevel();
> }
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 785892d6/log4j-api/src/main/java/org/apache/logging/log4j/
> util/Constants.java
> ----------------------------------------------------------------------
> diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
> b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
> index c20d446..c0d18d7 100644
> --- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
> +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
> @@ -53,6 +53,17 @@ public final class Constants {
> */
> public static final int MAX_REUSABLE_MESSAGE_SIZE = size("log4j.maxReusableMsgSize",
> (128 * 2 + 2) * 2 + 2);
>
> + /**
> + * Name of the system property that will turn on TRACE level internal
> log4j2 status logging.
> + * <p>
> + * If system property {@value} is defined, regardless of the property
> value, all internal log4j2 logging will be
> + * printed to the console. The presence of this system property
> overrides any value set in the configuration's
> + * {@code <Configuration status="<level>" ...>} status attribute, as
> well as any value set for
> + * system property {@code org.apache.logging.log4j.
> simplelog.StatusLogger.level}.
> + * </p>
> + */
> + public static final String LOG4J2_DEBUG = "log4j2.debug";
> +
> private static int size(final String property, final int
> defaultValue) {
> return PropertiesUtil.getProperties().getIntegerProperty(property,
> defaultValue);
> }
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 785892d6/log4j-api/src/main/java/org/apache/logging/log4j/
> util/PropertiesUtil.java
> ----------------------------------------------------------------------
> diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
> b/log4j-api/src/main/java/org/apache/logging/log4j/util/
> PropertiesUtil.java
> index 16b9ef6..9d99aee 100644
> --- a/log4j-api/src/main/java/org/apache/logging/log4j/util/
> PropertiesUtil.java
> +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/
> PropertiesUtil.java
> @@ -101,6 +101,15 @@ public final class PropertiesUtil {
> }
>
> /**
> + * Returns {@code true} if the specified property is defined,
> regardless of its value (it may not have a value).
> + * @param name the name of the property to verify
> + * @return {@code true} if the specified property is defined,
> regardless of its value
> + */
> + public boolean hasProperty(final String name) {
> + return System.getProperties().containsKey(name) ||
> props.containsKey(name);
> + }
> +
> + /**
> * Gets the named property as a boolean value. If the property
> matches the string {@code "true"} (case-insensitive),
> * then it is returned as the boolean value {@code true}. Any other
> non-{@code null} text in the property is
> * considered {@code false}.
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 785892d6/log4j-core/src/main/java/org/apache/logging/log4j/core/config/
> ConfigurationFactory.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/
> config/ConfigurationFactory.java b/log4j-core/src/main/java/
> org/apache/logging/log4j/core/config/ConfigurationFactory.java
> index 8b360a5..adefd31 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/
> config/ConfigurationFactory.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
> config/ConfigurationFactory.java
> @@ -465,8 +465,8 @@ public abstract class ConfigurationFactory extends
> ConfigurationBuilderFactory {
> }
> LOGGER.error("No log4j2 configuration file found. " +
> "Using default configuration: logging only errors to
> the console. " +
> - "Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level'"
> +
> - " to TRACE to show Log4j2 internal initialization
> logging.");
> + "Set system property 'log4j2.debug' " +
> + "to show Log4j2 internal initialization logging.");
> return new DefaultConfiguration();
> }
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 785892d6/src/changes/changes.xml
> ----------------------------------------------------------------------
> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> index 13783c6..1e32a53 100644
> --- a/src/changes/changes.xml
> +++ b/src/changes/changes.xml
> @@ -31,6 +31,9 @@
> - "remove" - Removed
> -->
> <release version="2.9.0" date="2017-MM-DD" description="GA Release
> 2.9.0">
> + <action issue="LOG4J2-1813" dev="rpopma" type="add">
> + Log4j2 will now print all internal logging to the console if
> system property `log4j2.debug` is defined with any value (or no value).
> + </action>
> <action issue="LOG4J2-1908" dev="rpopma" type="update">
> Improved error message when misconfigured with multiple
> incompatible appenders targeting same file.
> </action>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 785892d6/src/site/markdown/faq.md.vm
> ----------------------------------------------------------------------
> diff --git a/src/site/markdown/faq.md.vm b/src/site/markdown/faq.md.vm
> index ece776b..132e6fe 100644
> --- a/src/site/markdown/faq.md.vm
> +++ b/src/site/markdown/faq.md.vm
> @@ -35,7 +35,7 @@ $h1 Frequently Asked Questions
> * [How do I set my log archive retention policy? How do I delete old log
> archives?](#retention)
> * [What are the trade-offs of using the Log4j 2 API versus the SLF4J
> API?](#api-tradeoffs)
> * [Is Log4j 2 still garbage-free when I use the SLF4J
> API?](#gc-free-slf4j)
> -* [How do I log my domain object without creating
> garbage?](#gc-free-domain-object)
> +* [How do I log my domain object without creating
> garbage?](#gc-free-domain-object)
> * [How do I create a custom logger wrapper that shows the correct class,
> method and line number?](#logger-wrapper)
>
> <a name="missing_core"/>
> @@ -281,6 +281,15 @@ Next, check the name of your configuration file. By
> default, log4j2 will look
> for a configuration file named `log4j2.xml` on the classpath. Note the
> "2" in the file name!
> (See the [configuration manual page](manual/configuration.html#AutomaticConfiguration)
> for more details.)
>
> +**From log4j-2.9 onward**
> +
> +From log4j-2.9 onward, log4j2 will print all internal logging to the
> console if system property `log4j2.debug`
> +is defined (with any or no value).
> +
> +**Prior to log4j-2.9**
> +
> +Prior to log4j-2.9, there are two places where internal logging can be
> controlled:
> +
> If the configuration file is found correctly, log4j2 internal status
> logging can be controlled by
> setting `<Configuration status="trace">` in the configuration file. This
> will display detailed log4j2-internal
> log statements on the console about what happens during the configuration
> process.
> @@ -354,7 +363,7 @@ You can use the `ThreadContext` map value to determine
> the log file name.
> <a name="reconfig_level_from_code"/>
> $h4 How do I set a logger's level programmatically?
>
> -You can set a logger's level with the class
> +You can set a logger's level with the class
> [`Configurator`](log4j-core/apidocs/org/apache/logging/log4j/core/config/
> Configurator.html)
> from Log4j Core. Be aware that the `Configurator` class is not part of
> the public API.
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
> 785892d6/src/site/xdoc/manual/configuration.xml.vm
> ----------------------------------------------------------------------
> diff --git a/src/site/xdoc/manual/configuration.xml.vm
> b/src/site/xdoc/manual/configuration.xml.vm
> index b70b306..fcfff70 100644
> --- a/src/site/xdoc/manual/configuration.xml.vm
> +++ b/src/site/xdoc/manual/configuration.xml.vm
> @@ -425,11 +425,15 @@ public class Bar {
> </tr>
> <tr>
> <td>status</td>
> - <td>The level of internal Log4j events that should be
> logged to the console.
> + <td><p>The level of internal Log4j events that should be
> logged to the console.
> Valid values for this attribute are "trace", "debug",
> "info", "warn", "error" and "fatal".
> Log4j will log details about initialization, rollover and
> other internal actions to the status logger.
> Setting <tt>status="trace"</tt> is one of the first tools
> available to you if you need to
> - troubleshoot log4j.</td>
> + troubleshoot log4j.
> + </p><p>
> + (Alternatively, setting system property
> <tt>log4j2.debug</tt> will also print internal Log4j2 logging
> + to the console, including internal logging that took
> place before the configuration file was found.)
> + </p></td>
> </tr>
> <tr>
> <td>strict</td>
> @@ -1315,6 +1319,9 @@ rootLogger.appenderRef.stdout.ref = STDOUT
> <tr>
> <td>
> <b>Troubleshooting tip for the impatient:</b>
> + <p>From log4j-2.9 onward, log4j2 will print all internal
> logging to the console if system property
> + <tt>log4j2.debug</tt> is defined (with any or no
> value).</p>
> + <p>Prior to log4j-2.9, there are two places where internal
> logging can be controlled:</p>
> <ul>
> <li>Before a configuration is found, status logger level
> can be controlled with system
> property <code>org.apache.logging.
> log4j.simplelog.StatusLogger.level</code>.</li>
> @@ -1575,6 +1582,7 @@ public class AwesomeTest {
> <th>Default Value</th>
> <th>Description</th>
> </tr>
> +
> <tr>
> <td><a name="log4j.configurationFile"/>log4j.configurationFile</td>
> <td> </td>
> @@ -1584,6 +1592,14 @@ public class AwesomeTest {
> </td>
> </tr>
> <tr>
> + <td><a name="log4j2.debug"/>log4j2.debug</td>
> + <td> </td>
> + <td>
> + Log4j2 will print all internal logging to the console if system
> property
> + <tt>log4j2.debug</tt> is defined (with any or no value).
> + </td>
> + </tr>
> + <tr>
> <td><a name="log4j.mergeFactory"/>log4j.mergeFactory</td>
> <td> </td>
> <td>
>
>
--
Matt Sicker <bo...@gmail.com>