[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-11-g7172853

This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Logback: the generic, reliable, fast and flexible logging framework.". The branch, master has been updated via 7172853f27b3339eb1c1790f96f46c0162bdf141 (commit) from 3b58f83f64a4b00f17505f112cd5831232ae4a8b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=7172853f27b3339eb1c1790f9... http://github.com/ceki/logback/commit/7172853f27b3339eb1c1790f96f46c0162bdf1... commit 7172853f27b3339eb1c1790f96f46c0162bdf141 Author: Ceki Gulcu <ceki@qos.ch> Date: Tue Jan 26 21:59:45 2010 +0100 - In logback-classic ConfigurationAction, the HOSTNAME property is now automatically defined and added to the logger context. This value comes in handy in a variety of situations. diff --git a/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java b/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java index ed776dc..7e766f0 100644 --- a/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java +++ b/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java @@ -17,6 +17,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.spi.InterpretationContext; +import ch.qos.logback.core.util.ContextUtil; import ch.qos.logback.core.util.StatusPrinter; @@ -36,6 +37,8 @@ public class ConfigurationAction extends Action { debugMode = true; } + new ContextUtil(context).addHostNameAsProperty(); + // the context is appender attachable, so it is pushed on top of the stack ec.pushObject(getContext()); } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java index 6475778..3eef4b4 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java @@ -19,6 +19,7 @@ import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter; import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.spi.InterpretationContext; +import ch.qos.logback.core.util.ContextUtil; import ch.qos.logback.core.util.Duration; import ch.qos.logback.core.util.OptionHelper; import ch.qos.logback.core.util.StatusPrinter; @@ -38,14 +39,13 @@ public class ConfigurationAction extends Action { || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { - // LoggerContext loggerContext = (LoggerContext) context; - // ConfiguratorBase.attachTemporaryConsoleAppender(context); - debugMode = true; } processScanAttrib(attributes); + new ContextUtil(context).addHostNameAsProperty(); + // the context is turbo filter attachable, so it is pushed on top of the // stack ec.pushObject(getContext()); diff --git a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java index ac1d8fd..a57425f 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java +++ b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java @@ -104,4 +104,11 @@ public class CoreConstants { // configuration, then file.getURL() is registered public static String URL_OF_LAST_CONFIGURATION_VIA_JORAN = "URL_OF_LAST_CONFIGURATION_VIA_JORAN"; + + /** + * The key under which the local host name is registered in the logger + * context. + */ + public static final String HOSTNAME_KEY = "HOSTNAME"; + } diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/ContextUtil.java b/logback-core/src/main/java/ch/qos/logback/core/util/ContextUtil.java new file mode 100644 index 0000000..f10afcb --- /dev/null +++ b/logback-core/src/main/java/ch/qos/logback/core/util/ContextUtil.java @@ -0,0 +1,42 @@ +/** + * Logback: the reliable, generic, fast and flexible logging framework. + * Copyright (C) 1999-2010, QOS.ch. All rights reserved. + * + * This program and the accompanying materials are dual-licensed under either + * the terms of the Eclipse Public License v1.0 as published by the Eclipse + * Foundation + * + * or (per the licensee's choosing) + * + * under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + */ +package ch.qos.logback.core.util; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import ch.qos.logback.core.Context; +import ch.qos.logback.core.CoreConstants; +import ch.qos.logback.core.spi.ContextAwareBase; + +public class ContextUtil extends ContextAwareBase { + + public ContextUtil(Context context) { + setContext(context); + } + + /** + * Add the local host's name as a property + */ + public void addHostNameAsProperty() { + try { + InetAddress localhost = InetAddress.getLocalHost(); + context.putProperty(CoreConstants.HOSTNAME_KEY, localhost.getHostName()); + } catch (UnknownHostException e) { + addError("Failed to get local hostname", e); + } catch (SecurityException e) { + addError("Failed to get local hostname", e); + } + } +} diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/SystemInfo.java b/logback-core/src/main/java/ch/qos/logback/core/util/SystemInfo.java index e2d701f..e423939 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/util/SystemInfo.java +++ b/logback-core/src/main/java/ch/qos/logback/core/util/SystemInfo.java @@ -13,10 +13,12 @@ */ package ch.qos.logback.core.util; -public class SystemInfo { + +public class SystemInfo { public static String getJavaVendor() { return OptionHelper.getSystemProperty("java.vendor", null); } + } diff --git a/logback-site/src/site/pages/manual/configuration.html b/logback-site/src/site/pages/manual/configuration.html index 169360a..d3a135e 100644 --- a/logback-site/src/site/pages/manual/configuration.html +++ b/logback-site/src/site/pages/manual/configuration.html @@ -1148,7 +1148,8 @@ public class MyApp3 { sequence. For example, if <em>java.home.dir</em> system property is set to <em>/home/xyz</em>, then every occurrence of the sequence <em>${java.home.dir}</em> will be interpreted as <em>/home/xyz</em>. - </p> + As it often comes in handy, the variable ${HOSTNAME} is + automatically defined.</p> <h4>properties are inserted into the logger context</h4> ----------------------------------------------------------------------- Summary of changes: .../access/joran/action/ConfigurationAction.java | 3 + .../classic/joran/action/ConfigurationAction.java | 6 +- .../java/ch/qos/logback/core/CoreConstants.java | 7 +++ .../java/ch/qos/logback/core/util/ContextUtil.java | 42 ++++++++++++++++++++ .../java/ch/qos/logback/core/util/SystemInfo.java | 4 +- .../src/site/pages/manual/configuration.html | 3 +- 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 logback-core/src/main/java/ch/qos/logback/core/util/ContextUtil.java hooks/post-receive -- Logback: the generic, reliable, fast and flexible logging framework.
participants (1)
-
git-noreply@pixie.qos.ch