Commit af77674e authored by Tom Evans's avatar Tom Evans Committed by Dave Cridland

OF-460: Persist log.debug.enabled property

Fix settings for debug log so the admin UI setting is retained across
restarts. The system property "log.debug.enabled" may also be used to
manage this setting. If provided via openfire.xml, the property will be
migrated into the DB during startup.
parent 705864ad
......@@ -63,7 +63,25 @@ import org.jivesoftware.openfire.disco.UserItemsProvider;
import org.jivesoftware.openfire.filetransfer.DefaultFileTransferManager;
import org.jivesoftware.openfire.filetransfer.FileTransferManager;
import org.jivesoftware.openfire.filetransfer.proxy.FileTransferProxy;
import org.jivesoftware.openfire.handler.*;
import org.jivesoftware.openfire.handler.IQAuthHandler;
import org.jivesoftware.openfire.handler.IQBindHandler;
import org.jivesoftware.openfire.handler.IQEntityTimeHandler;
import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.openfire.handler.IQLastActivityHandler;
import org.jivesoftware.openfire.handler.IQMessageCarbonsHandler;
import org.jivesoftware.openfire.handler.IQOfflineMessagesHandler;
import org.jivesoftware.openfire.handler.IQPingHandler;
import org.jivesoftware.openfire.handler.IQPrivacyHandler;
import org.jivesoftware.openfire.handler.IQPrivateHandler;
import org.jivesoftware.openfire.handler.IQRegisterHandler;
import org.jivesoftware.openfire.handler.IQRosterHandler;
import org.jivesoftware.openfire.handler.IQSessionEstablishmentHandler;
import org.jivesoftware.openfire.handler.IQSharedGroupHandler;
import org.jivesoftware.openfire.handler.IQTimeHandler;
import org.jivesoftware.openfire.handler.IQVersionHandler;
import org.jivesoftware.openfire.handler.IQvCardHandler;
import org.jivesoftware.openfire.handler.PresenceSubscribeHandler;
import org.jivesoftware.openfire.handler.PresenceUpdateHandler;
import org.jivesoftware.openfire.lockout.LockOutManager;
import org.jivesoftware.openfire.mediaproxy.MediaProxyService;
import org.jivesoftware.openfire.muc.MultiUserChatManager;
......@@ -90,6 +108,7 @@ import org.jivesoftware.util.CertificateManager;
import org.jivesoftware.util.InitializationException;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.util.Version;
import org.jivesoftware.util.cache.CacheFactory;
......@@ -128,7 +147,7 @@ import org.xmpp.packet.JID;
*/
public class XMPPServer {
private static final Logger Log = LoggerFactory.getLogger(XMPPServer.class);
private static final Logger logger = LoggerFactory.getLogger(XMPPServer.class);
private static XMPPServer instance;
......@@ -337,7 +356,7 @@ public class XMPPServer {
host = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException ex) {
Log.warn("Unable to determine local hostname.", ex);
logger.warn("Unable to determine local hostname.", ex);
}
if (host == null) {
host = "127.0.0.1";
......@@ -349,7 +368,7 @@ public class XMPPServer {
}
if (isStandAlone()) {
Log.info("Registering shutdown hook (standalone mode)");
logger.info("Registering shutdown hook (standalone mode)");
Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
TaskEngine.getInstance().schedule(new Terminator(), 1000, 1000);
}
......@@ -360,18 +379,18 @@ public class XMPPServer {
CacheFactory.initialize();
} catch (InitializationException e) {
e.printStackTrace();
Log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
}
JiveGlobals.migrateProperty("xmpp.domain");
name = JiveGlobals.getProperty("xmpp.domain", host).toLowerCase();
org.jivesoftware.util.Log.setDebugEnabled(JiveGlobals.getXMLProperty("log.debug.enabled", false));
JiveGlobals.migrateProperty(Log.LOG_DEBUG_ENABLED);
Log.setDebugEnabled(JiveGlobals.getBooleanProperty(Log.LOG_DEBUG_ENABLED, false));
// Update server info
xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate);
initialized = true;
}
......@@ -420,7 +439,7 @@ public class XMPPServer {
}
} catch (Exception e) {
Log.error("Error generating self-signed certificates", e);
logger.error("Error generating self-signed certificates", e);
}
// Initialize list of admins now (before we restart Jetty)
......@@ -454,7 +473,7 @@ public class XMPPServer {
}
catch (Exception e) {
e.printStackTrace();
Log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
shutdownServer();
}
}
......@@ -495,7 +514,7 @@ public class XMPPServer {
// Log that the server has been started
String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() +
" [" + JiveGlobals.formatDateTime(new Date()) + "]";
Log.info(startupBanner);
logger.info(startupBanner);
System.out.println(startupBanner);
started = true;
......@@ -507,7 +526,7 @@ public class XMPPServer {
}
catch (Exception e) {
e.printStackTrace();
Log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
System.out.println(LocaleUtils.getLocalizedString("startup.error"));
shutdownServer();
}
......@@ -588,7 +607,7 @@ public class XMPPServer {
}
catch (Exception e) {
e.printStackTrace();
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
......@@ -607,7 +626,7 @@ public class XMPPServer {
module.stop();
module.destroy();
}
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
......@@ -628,7 +647,7 @@ public class XMPPServer {
module.stop();
module.destroy();
}
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
......@@ -645,7 +664,7 @@ public class XMPPServer {
restartMethod.invoke(null, (Object []) null);
}
catch (Exception e) {
Log.error("Could not restart container", e);
logger.error("Could not restart container", e);
}
}
}
......@@ -685,7 +704,7 @@ public class XMPPServer {
* inside of another server.
*/
public void stop() {
Log.info("Initiating shutdown ...");
logger.info("Initiating shutdown ...");
// Only do a system exit if we're running standalone
if (isStandAlone()) {
// if we're in a wrapper, we have to tell the wrapper to shut us down
......@@ -696,7 +715,7 @@ public class XMPPServer {
stopMethod.invoke(null, 0);
}
catch (Exception e) {
Log.error("Could not stop container", e);
logger.error("Could not stop container", e);
}
}
else {
......@@ -763,7 +782,7 @@ public class XMPPServer {
System.err.println("Database setup or configuration error: " +
"Please verify your database settings and check the " +
"logs/error.log file for detailed error messages.");
Log.error("Database could not be accessed", e);
logger.error("Database could not be accessed", e);
throw new IllegalArgumentException(e);
}
finally {
......@@ -900,7 +919,7 @@ public class XMPPServer {
}
}
} catch (IOException ioe) {
Log.error("Error reading console input", ioe);
logger.error("Error reading console input", ioe);
}
}
}
......@@ -920,7 +939,7 @@ public class XMPPServer {
@Override
public void run() {
shutdownServer();
Log.info("Server halted");
logger.info("Server halted");
System.err.println("Server halted");
}
}
......@@ -962,30 +981,30 @@ public class XMPPServer {
try {
listener.serverStopping();
} catch (Exception ex) {
Log.error("Exception during listener shutdown", ex);
logger.error("Exception during listener shutdown", ex);
}
}
// If we don't have modules then the server has already been shutdown
if (modules.isEmpty()) {
return;
}
Log.info("Shutting down " + modules.size() + " modules ...");
logger.info("Shutting down " + modules.size() + " modules ...");
// Get all modules and stop and destroy them
for (Module module : modules.values()) {
try {
module.stop();
module.destroy();
} catch (Exception ex) {
Log.error("Exception during module shutdown", ex);
logger.error("Exception during module shutdown", ex);
}
}
// Stop all plugins
Log.info("Shutting down plugins ...");
logger.info("Shutting down plugins ...");
if (pluginManager != null) {
try {
pluginManager.shutdown();
} catch (Exception ex) {
Log.error("Exception during plugin shutdown", ex);
logger.error("Exception during plugin shutdown", ex);
}
}
modules.clear();
......@@ -993,14 +1012,14 @@ public class XMPPServer {
try {
DbConnectionManager.destroyConnectionProvider();
} catch (Exception ex) {
Log.error("Exception during DB shutdown", ex);
logger.error("Exception during DB shutdown", ex);
}
// Shutdown the task engine.
TaskEngine.getInstance().shutdown();
// hack to allow safe stopping
Log.info("Openfire stopped");
logger.info("Openfire stopped");
}
/**
......
......@@ -28,6 +28,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Openfire makes use of a logging facade (slf4j) to manage its log output. The
......@@ -46,17 +47,32 @@ import java.util.List;
public class Log {
private static final org.slf4j.Logger Logger = org.slf4j.LoggerFactory.getLogger(Log.class);
public static final String LOG_DEBUG_ENABLED = "log.debug.enabled";
// listen for changes to the log.debug.enabled property
static {
PropertyEventDispatcher.addListener(new PropertyEventListener() {
public void propertySet(String property, Map<String, Object> params) {
enableDebugLog(property, Boolean.parseBoolean(params.get("value").toString()));
}
public void propertyDeleted(String property, Map<String, Object> params) {
enableDebugLog(property, false);
}
// ignore these events
public void xmlPropertySet(String property, Map<String, Object> params) { }
public void xmlPropertyDeleted(String property, Map<String, Object> params) { }
private void enableDebugLog(String property, boolean enabled) {
if ((LOG_DEBUG_ENABLED).equals(property)) {
Log.setDebugEnabled(enabled);
}
}
});
}
// TODO deprecate these properties
// JiveGlobals.getXMLProperty("log.debug.format");
// JiveGlobals.getXMLProperty("log.info.format");
// JiveGlobals.getXMLProperty("log.warn.format");
// JiveGlobals.getXMLProperty("log.error.format");
// JiveGlobals.getXMLProperty("log.debug.size");
// JiveGlobals.getXMLProperty("log.info.size");
// JiveGlobals.getXMLProperty("log.warn.size");
// JiveGlobals.getXMLProperty("log.error.size");
// JiveGlobals.getXMLProperty("log.debug.enabled");
/**
* @deprecated replaced by {@link org.slf4j.Logger#isErrorEnabled()}.
......
......@@ -129,11 +129,10 @@
boolean saveLog = ParamUtils.getBooleanParameter(request,"saveLog");
boolean emailLog = ParamUtils.getBooleanParameter(request,"emailLog");
boolean debugEnabled = ParamUtils.getBooleanParameter(request,"debugEnabled");
boolean wasDebugEnabled = ParamUtils.getBooleanParameter(request,"wasDebugEnabled");
// Enable/disable debugging
if (request.getParameter("wasDebugEnabled") != null && wasDebugEnabled != debugEnabled) {
Log.setDebugEnabled(debugEnabled);
if (request.getParameter("debugEnabled") != null && debugEnabled != Log.isDebugEnabled()) {
JiveGlobals.setProperty(Log.LOG_DEBUG_ENABLED, String.valueOf(debugEnabled));
// Log the event
admin.logEvent((debugEnabled ? "enabled" : "disabled")+" debug logging", null);
response.sendRedirect("logviewer.jsp?log=debug");
......@@ -409,19 +408,18 @@ IFRAME {
<fmt:message key="logviewer.debug_log" />: &nbsp;
</td>
<td width="1%">
<input type="radio" name="debugEnabled" value="true"<%= ((debugEnabled) ? " checked" : "") %> id="de01">
<input id="de01" type="radio" name="debugEnabled" value="true" <%= debugEnabled ? " checked" : "" %>>
</td>
<td width="1%" nowrap>
<label for="de01"><fmt:message key="logviewer.enabled" /></label> &nbsp;
</td>
<td width="1%">
<input type="radio" name="debugEnabled" value="false"<%= ((!debugEnabled) ? " checked" : "") %> id="de02">
<input id="de02" type="radio" name="debugEnabled" value="false" <%= debugEnabled ? "" : " checked" %>>
</td>
<td width="1%" nowrap>
<label for="de02">Disabled</label> &nbsp;
</td>
<td width="1%">
<input type="hidden" name="wasDebugEnabled" value="<%= debugEnabled %>">
<input type="submit" name="" value="<fmt:message key="global.save_changes" />">
</td>
<td width="94%">&nbsp;</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment