[jboss-cvs] JBossAS SVN: r81182 - in trunk/server/src: etc/conf/default/xmdesc and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 17 16:35:43 EST 2008
Author: bstansberry at jboss.com
Date: 2008-11-17 16:35:43 -0500 (Mon, 17 Nov 2008)
New Revision: 81182
Added:
trunk/server/src/main/org/jboss/logging/SysPropertyActions.java
Modified:
trunk/server/src/etc/conf/default/jboss-log4j.xml
trunk/server/src/etc/conf/default/jboss-minimal.xml
trunk/server/src/etc/conf/default/jboss-service.xml
trunk/server/src/etc/conf/default/xmdesc/Log4jService-xmbean.xml
trunk/server/src/main/org/jboss/logging/Log4jService.java
trunk/server/src/main/org/jboss/logging/Log4jServiceMBean.java
Log:
[JBAS-6205] Make server.log logging level configurable via system property
Modified: trunk/server/src/etc/conf/default/jboss-log4j.xml
===================================================================
--- trunk/server/src/etc/conf/default/jboss-log4j.xml 2008-11-17 20:23:47 UTC (rev 81181)
+++ trunk/server/src/etc/conf/default/jboss-log4j.xml 2008-11-17 21:35:43 UTC (rev 81182)
@@ -25,6 +25,12 @@
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
+ <!--
+ Set the threshold via a system property. Note this is parsed by log4j,
+ so the full JBoss system property format is not supported; e.g.
+ setting a default via ${jboss.server.log.threshold:WARN} will not work.
+ -->
+ <param name="Threshold" value="${jboss.server.log.threshold}"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
Modified: trunk/server/src/etc/conf/default/jboss-minimal.xml
===================================================================
--- trunk/server/src/etc/conf/default/jboss-minimal.xml 2008-11-17 20:23:47 UTC (rev 81181)
+++ trunk/server/src/etc/conf/default/jboss-minimal.xml 2008-11-17 21:35:43 UTC (rev 81182)
@@ -19,7 +19,13 @@
<!-- ==================================================================== -->
<mbean code="org.jboss.logging.Log4jService"
name="jboss.system:type=Log4jService,service=Logging">
- <attribute name="ConfigurationURL">resource:jboss-log4j.xml</attribute>
+ <attribute name="ConfigurationURL">resource:jboss-log4j.xml</attribute>
+ <!-- The value to assign to system property jboss.server.log.threshold
+ if it is not already set. This system property in turn controls
+ the logging threshold for the server.log file.
+ If the system property is already set when this service is created,
+ this value is ignored. -->
+ <attribute name="DefaultJBossServerLogThreshold">DEBUG</attribute>
</mbean>
<!-- A Thread pool service -->
Modified: trunk/server/src/etc/conf/default/jboss-service.xml
===================================================================
--- trunk/server/src/etc/conf/default/jboss-service.xml 2008-11-17 20:23:47 UTC (rev 81181)
+++ trunk/server/src/etc/conf/default/jboss-service.xml 2008-11-17 21:35:43 UTC (rev 81182)
@@ -81,6 +81,13 @@
<attribute name="Log4jQuietMode">true</attribute>
<!-- How frequently in seconds the ConfigurationURL is checked for changes -->
<attribute name="RefreshPeriod">60</attribute>
+
+ <!-- The value to assign to system property jboss.server.log.threshold
+ if it is not already set. This system property in turn controls
+ the logging threshold for the server.log file.
+ If the system property is already set when this service is created,
+ this value is ignored. -->
+ <attribute name="DefaultJBossServerLogThreshold">DEBUG</attribute>
</mbean>
<!-- ==================================================================== -->
Modified: trunk/server/src/etc/conf/default/xmdesc/Log4jService-xmbean.xml
===================================================================
--- trunk/server/src/etc/conf/default/xmdesc/Log4jService-xmbean.xml 2008-11-17 20:23:47 UTC (rev 81181)
+++ trunk/server/src/etc/conf/default/xmdesc/Log4jService-xmbean.xml 2008-11-17 21:35:43 UTC (rev 81182)
@@ -46,6 +46,13 @@
<name>RefreshPeriod</name>
<type>int</type>
</attribute>
+ <attribute access="read-write" getMethod="getDefaultJBossServerLogThreshold" setMethod="setDefaultJBossServerLogThreshold">
+ <description>The value to assign to system property jboss.server.log.threshold
+ if it is not already set. This system property in turn controls
+ the logging threshold for the server.log file.</description>
+ <name>DefaultJBossServerLogThreshold</name>
+ <type>java.lang.String</type>
+ </attribute>
<!-- Operations -->
<operation>
<description>Displays the log level of a given logger.</description>
Modified: trunk/server/src/main/org/jboss/logging/Log4jService.java
===================================================================
--- trunk/server/src/main/org/jboss/logging/Log4jService.java 2008-11-17 20:23:47 UTC (rev 81181)
+++ trunk/server/src/main/org/jboss/logging/Log4jService.java 2008-11-17 21:35:43 UTC (rev 81182)
@@ -94,6 +94,12 @@
*/
public static final boolean CATCH_SYSTEM_ERR =
getBoolean(Log4jService.class.getName() + ".catchSystemErr", true);
+
+ /**
+ * Default value for system property {@link #JBOSS_SERVER_LOG_THRESHOLD_PROPERTY}
+ * if it is not otherwise configured.
+ */
+ public static final String DEFAULT_JBOSS_SERVER_LOG_THRESHOLD = "DEBUG";
/** Helper to get boolean value from system property or use default if not set. */
private static boolean getBoolean(String name, boolean defaultValue)
@@ -132,6 +138,8 @@
/** The org.apache.log4j.helpers.LogLog.setQuietMode flag setting */
private boolean log4jQuietMode = true;
+
+ private String defaultJBossServerLogLevel = DEFAULT_JBOSS_SERVER_LOG_THRESHOLD;
/** The URL watch timer (in daemon mode). */
private Timer timer;
@@ -314,6 +322,26 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @jmx:managed-attribute
+ */
+ public String getDefaultJBossServerLogThreshold()
+ {
+ return defaultJBossServerLogLevel;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @jmx:managed-attribute
+ */
+ public void setDefaultJBossServerLogThreshold(String level)
+ {
+ this.defaultJBossServerLogLevel = level;
+ }
+
+ /**
* Sets the level for a logger of the give name.
*
* <p>Values are trimmed before used.
@@ -325,7 +353,7 @@
*/
public void setLoggerLevel(final String name, final String levelName)
{
- org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(name.trim());
+ org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(name.trim());
Level level = XLevel.toLevel(levelName.trim());
logger.setLevel(level);
@@ -456,6 +484,8 @@
{
if (initialized) return;
+ establishDefaultLoggingLevelSystemProperty();
+
timerTask = new URLWatchTimerTask();
timerTask.run();
timer = new Timer("Timer-" + getName(), true);
@@ -472,6 +502,25 @@
initialized = true;
}
+ private void establishDefaultLoggingLevelSystemProperty()
+ {
+ try
+ {
+ if (defaultJBossServerLogLevel != null
+ && SysPropertyActions.getProperty(JBOSS_SERVER_LOG_THRESHOLD_PROPERTY, null) == null)
+ {
+ SysPropertyActions.setProperty(JBOSS_SERVER_LOG_THRESHOLD_PROPERTY,
+ defaultJBossServerLogLevel);
+ }
+ }
+ catch (SecurityException e)
+ {
+ log.warn("Cannot configure system property " + JBOSS_SERVER_LOG_THRESHOLD_PROPERTY +
+ " -- " + e.getLocalizedMessage());
+ }
+
+ }
+
protected void createService() throws Exception
{
setup();
Modified: trunk/server/src/main/org/jboss/logging/Log4jServiceMBean.java
===================================================================
--- trunk/server/src/main/org/jboss/logging/Log4jServiceMBean.java 2008-11-17 20:23:47 UTC (rev 81181)
+++ trunk/server/src/main/org/jboss/logging/Log4jServiceMBean.java 2008-11-17 21:35:43 UTC (rev 81182)
@@ -41,6 +41,9 @@
/** Notification type used to indicate a log4j reconfiguration */
String RECONFIGURE_NOTIFICATION_TYPE = "jboss.logging.log4j.reconfigure";
+ /** Name of system property used to control the logging threshold for the server.log file */
+ String JBOSS_SERVER_LOG_THRESHOLD_PROPERTY = "jboss.server.log.threshold";
+
// Attributes ----------------------------------------------------
/**
@@ -76,6 +79,18 @@
void setConfigurationURL(URL url);
URL getConfigurationURL();
+ /**
+ * The value to assign to system property {@link #JBOSS_SERVER_LOG_THRESHOLD_PROPERTY}
+ * if it is not already set. This system property in turn controls
+ * the logging threshold for the server.log file.
+ * <p>
+ * If the system property is already set when this service is created,
+ * this value is ignored.
+ * </p>
+ */
+ void setDefaultJBossServerLogThreshold(String level);
+ String getDefaultJBossServerLogThreshold();
+
// Operations ----------------------------------------------------
/**
Added: trunk/server/src/main/org/jboss/logging/SysPropertyActions.java
===================================================================
--- trunk/server/src/main/org/jboss/logging/SysPropertyActions.java (rev 0)
+++ trunk/server/src/main/org/jboss/logging/SysPropertyActions.java 2008-11-17 21:35:43 UTC (rev 81182)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.logging;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged actions for the package
+ *
+ * @author Scott.Stark at jboss.org
+ * @author Brian Stansberry
+ * @version $Revision: 2787 $
+ *
+ */
+class SysPropertyActions
+{
+ interface SysProps
+ {
+ SysProps NON_PRIVILEGED = new SysProps()
+ {
+ public String getProperty(final String name, final String defaultValue)
+ {
+ return System.getProperty(name, defaultValue);
+ }
+
+ public String setProperty(final String name, final String value)
+ {
+ return System.setProperty(name, value);
+ }
+ };
+ SysProps PRIVILEGED = new SysProps()
+ {
+ public String getProperty(final String name, final String defaultValue)
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ return (String) AccessController.doPrivileged(action);
+ }
+
+ public String setProperty(final String name, final String value)
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.setProperty(name, value);
+ }
+ };
+ return (String) AccessController.doPrivileged(action);
+ }
+ };
+ String getProperty(String name, String defaultValue);
+ String setProperty(final String name, final String value);
+ }
+
+ public static String getProperty(String name, String defaultValue)
+ {
+ String prop;
+ if( System.getSecurityManager() == null )
+ prop = SysProps.NON_PRIVILEGED.getProperty(name, defaultValue);
+ else
+ prop = SysProps.PRIVILEGED.getProperty(name, defaultValue);
+ return prop;
+ }
+
+ public static String setProperty(String name, String value)
+ {
+ String prop;
+ if( System.getSecurityManager() == null )
+ prop = SysProps.NON_PRIVILEGED.setProperty(name, value);
+ else
+ prop = SysProps.PRIVILEGED.setProperty(name, value);
+ return prop;
+ }
+}
More information about the jboss-cvs-commits
mailing list