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; ...@@ -63,7 +63,25 @@ import org.jivesoftware.openfire.disco.UserItemsProvider;
import org.jivesoftware.openfire.filetransfer.DefaultFileTransferManager; import org.jivesoftware.openfire.filetransfer.DefaultFileTransferManager;
import org.jivesoftware.openfire.filetransfer.FileTransferManager; import org.jivesoftware.openfire.filetransfer.FileTransferManager;
import org.jivesoftware.openfire.filetransfer.proxy.FileTransferProxy; 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.lockout.LockOutManager;
import org.jivesoftware.openfire.mediaproxy.MediaProxyService; import org.jivesoftware.openfire.mediaproxy.MediaProxyService;
import org.jivesoftware.openfire.muc.MultiUserChatManager; import org.jivesoftware.openfire.muc.MultiUserChatManager;
...@@ -90,6 +108,7 @@ import org.jivesoftware.util.CertificateManager; ...@@ -90,6 +108,7 @@ import org.jivesoftware.util.CertificateManager;
import org.jivesoftware.util.InitializationException; import org.jivesoftware.util.InitializationException;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine; import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.util.Version; import org.jivesoftware.util.Version;
import org.jivesoftware.util.cache.CacheFactory; import org.jivesoftware.util.cache.CacheFactory;
...@@ -128,7 +147,7 @@ import org.xmpp.packet.JID; ...@@ -128,7 +147,7 @@ import org.xmpp.packet.JID;
*/ */
public class XMPPServer { 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; private static XMPPServer instance;
...@@ -337,7 +356,7 @@ public class XMPPServer { ...@@ -337,7 +356,7 @@ public class XMPPServer {
host = InetAddress.getLocalHost().getHostName(); host = InetAddress.getLocalHost().getHostName();
} }
catch (UnknownHostException ex) { catch (UnknownHostException ex) {
Log.warn("Unable to determine local hostname.", ex); logger.warn("Unable to determine local hostname.", ex);
} }
if (host == null) { if (host == null) {
host = "127.0.0.1"; host = "127.0.0.1";
...@@ -349,7 +368,7 @@ public class XMPPServer { ...@@ -349,7 +368,7 @@ public class XMPPServer {
} }
if (isStandAlone()) { if (isStandAlone()) {
Log.info("Registering shutdown hook (standalone mode)"); logger.info("Registering shutdown hook (standalone mode)");
Runtime.getRuntime().addShutdownHook(new ShutdownHookThread()); Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
TaskEngine.getInstance().schedule(new Terminator(), 1000, 1000); TaskEngine.getInstance().schedule(new Terminator(), 1000, 1000);
} }
...@@ -360,18 +379,18 @@ public class XMPPServer { ...@@ -360,18 +379,18 @@ public class XMPPServer {
CacheFactory.initialize(); CacheFactory.initialize();
} catch (InitializationException e) { } catch (InitializationException e) {
e.printStackTrace(); e.printStackTrace();
Log.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
JiveGlobals.migrateProperty("xmpp.domain"); JiveGlobals.migrateProperty("xmpp.domain");
name = JiveGlobals.getProperty("xmpp.domain", host).toLowerCase(); 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 // Update server info
xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate); xmppServerInfo = new XMPPServerInfoImpl(name, host, version, startDate);
initialized = true; initialized = true;
} }
...@@ -420,7 +439,7 @@ public class XMPPServer { ...@@ -420,7 +439,7 @@ public class XMPPServer {
} }
} catch (Exception e) { } 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) // Initialize list of admins now (before we restart Jetty)
...@@ -454,7 +473,7 @@ public class XMPPServer { ...@@ -454,7 +473,7 @@ public class XMPPServer {
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.error(e.getMessage(), e); logger.error(e.getMessage(), e);
shutdownServer(); shutdownServer();
} }
} }
...@@ -495,7 +514,7 @@ public class XMPPServer { ...@@ -495,7 +514,7 @@ public class XMPPServer {
// Log that the server has been started // Log that the server has been started
String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() + String startupBanner = LocaleUtils.getLocalizedString("short.title") + " " + version.getVersionString() +
" [" + JiveGlobals.formatDateTime(new Date()) + "]"; " [" + JiveGlobals.formatDateTime(new Date()) + "]";
Log.info(startupBanner); logger.info(startupBanner);
System.out.println(startupBanner); System.out.println(startupBanner);
started = true; started = true;
...@@ -507,7 +526,7 @@ public class XMPPServer { ...@@ -507,7 +526,7 @@ public class XMPPServer {
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.error(e.getMessage(), e); logger.error(e.getMessage(), e);
System.out.println(LocaleUtils.getLocalizedString("startup.error")); System.out.println(LocaleUtils.getLocalizedString("startup.error"));
shutdownServer(); shutdownServer();
} }
...@@ -588,7 +607,7 @@ public class XMPPServer { ...@@ -588,7 +607,7 @@ public class XMPPServer {
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
} }
...@@ -607,7 +626,7 @@ public class XMPPServer { ...@@ -607,7 +626,7 @@ public class XMPPServer {
module.stop(); module.stop();
module.destroy(); module.destroy();
} }
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
} }
} }
...@@ -628,7 +647,7 @@ public class XMPPServer { ...@@ -628,7 +647,7 @@ public class XMPPServer {
module.stop(); module.stop();
module.destroy(); module.destroy();
} }
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); logger.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
} }
} }
...@@ -645,7 +664,7 @@ public class XMPPServer { ...@@ -645,7 +664,7 @@ public class XMPPServer {
restartMethod.invoke(null, (Object []) null); restartMethod.invoke(null, (Object []) null);
} }
catch (Exception e) { catch (Exception e) {
Log.error("Could not restart container", e); logger.error("Could not restart container", e);
} }
} }
} }
...@@ -685,7 +704,7 @@ public class XMPPServer { ...@@ -685,7 +704,7 @@ public class XMPPServer {
* inside of another server. * inside of another server.
*/ */
public void stop() { public void stop() {
Log.info("Initiating shutdown ..."); logger.info("Initiating shutdown ...");
// Only do a system exit if we're running standalone // Only do a system exit if we're running standalone
if (isStandAlone()) { if (isStandAlone()) {
// if we're in a wrapper, we have to tell the wrapper to shut us down // if we're in a wrapper, we have to tell the wrapper to shut us down
...@@ -696,7 +715,7 @@ public class XMPPServer { ...@@ -696,7 +715,7 @@ public class XMPPServer {
stopMethod.invoke(null, 0); stopMethod.invoke(null, 0);
} }
catch (Exception e) { catch (Exception e) {
Log.error("Could not stop container", e); logger.error("Could not stop container", e);
} }
} }
else { else {
...@@ -763,7 +782,7 @@ public class XMPPServer { ...@@ -763,7 +782,7 @@ public class XMPPServer {
System.err.println("Database setup or configuration error: " + System.err.println("Database setup or configuration error: " +
"Please verify your database settings and check the " + "Please verify your database settings and check the " +
"logs/error.log file for detailed error messages."); "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); throw new IllegalArgumentException(e);
} }
finally { finally {
...@@ -900,7 +919,7 @@ public class XMPPServer { ...@@ -900,7 +919,7 @@ public class XMPPServer {
} }
} }
} catch (IOException ioe) { } catch (IOException ioe) {
Log.error("Error reading console input", ioe); logger.error("Error reading console input", ioe);
} }
} }
} }
...@@ -920,7 +939,7 @@ public class XMPPServer { ...@@ -920,7 +939,7 @@ public class XMPPServer {
@Override @Override
public void run() { public void run() {
shutdownServer(); shutdownServer();
Log.info("Server halted"); logger.info("Server halted");
System.err.println("Server halted"); System.err.println("Server halted");
} }
} }
...@@ -962,30 +981,30 @@ public class XMPPServer { ...@@ -962,30 +981,30 @@ public class XMPPServer {
try { try {
listener.serverStopping(); listener.serverStopping();
} catch (Exception ex) { } 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 we don't have modules then the server has already been shutdown
if (modules.isEmpty()) { if (modules.isEmpty()) {
return; return;
} }
Log.info("Shutting down " + modules.size() + " modules ..."); logger.info("Shutting down " + modules.size() + " modules ...");
// Get all modules and stop and destroy them // Get all modules and stop and destroy them
for (Module module : modules.values()) { for (Module module : modules.values()) {
try { try {
module.stop(); module.stop();
module.destroy(); module.destroy();
} catch (Exception ex) { } catch (Exception ex) {
Log.error("Exception during module shutdown", ex); logger.error("Exception during module shutdown", ex);
} }
} }
// Stop all plugins // Stop all plugins
Log.info("Shutting down plugins ..."); logger.info("Shutting down plugins ...");
if (pluginManager != null) { if (pluginManager != null) {
try { try {
pluginManager.shutdown(); pluginManager.shutdown();
} catch (Exception ex) { } catch (Exception ex) {
Log.error("Exception during plugin shutdown", ex); logger.error("Exception during plugin shutdown", ex);
} }
} }
modules.clear(); modules.clear();
...@@ -993,14 +1012,14 @@ public class XMPPServer { ...@@ -993,14 +1012,14 @@ public class XMPPServer {
try { try {
DbConnectionManager.destroyConnectionProvider(); DbConnectionManager.destroyConnectionProvider();
} catch (Exception ex) { } catch (Exception ex) {
Log.error("Exception during DB shutdown", ex); logger.error("Exception during DB shutdown", ex);
} }
// Shutdown the task engine. // Shutdown the task engine.
TaskEngine.getInstance().shutdown(); TaskEngine.getInstance().shutdown();
// hack to allow safe stopping // hack to allow safe stopping
Log.info("Openfire stopped"); logger.info("Openfire stopped");
} }
/** /**
......
...@@ -28,6 +28,7 @@ import java.io.PrintWriter; ...@@ -28,6 +28,7 @@ import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Openfire makes use of a logging facade (slf4j) to manage its log output. The * Openfire makes use of a logging facade (slf4j) to manage its log output. The
...@@ -46,17 +47,32 @@ import java.util.List; ...@@ -46,17 +47,32 @@ import java.util.List;
public class Log { public class Log {
private static final org.slf4j.Logger Logger = org.slf4j.LoggerFactory.getLogger(Log.class); 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()}. * @deprecated replaced by {@link org.slf4j.Logger#isErrorEnabled()}.
......
...@@ -129,11 +129,10 @@ ...@@ -129,11 +129,10 @@
boolean saveLog = ParamUtils.getBooleanParameter(request,"saveLog"); boolean saveLog = ParamUtils.getBooleanParameter(request,"saveLog");
boolean emailLog = ParamUtils.getBooleanParameter(request,"emailLog"); boolean emailLog = ParamUtils.getBooleanParameter(request,"emailLog");
boolean debugEnabled = ParamUtils.getBooleanParameter(request,"debugEnabled"); boolean debugEnabled = ParamUtils.getBooleanParameter(request,"debugEnabled");
boolean wasDebugEnabled = ParamUtils.getBooleanParameter(request,"wasDebugEnabled");
// Enable/disable debugging // Enable/disable debugging
if (request.getParameter("wasDebugEnabled") != null && wasDebugEnabled != debugEnabled) { if (request.getParameter("debugEnabled") != null && debugEnabled != Log.isDebugEnabled()) {
Log.setDebugEnabled(debugEnabled); JiveGlobals.setProperty(Log.LOG_DEBUG_ENABLED, String.valueOf(debugEnabled));
// Log the event // Log the event
admin.logEvent((debugEnabled ? "enabled" : "disabled")+" debug logging", null); admin.logEvent((debugEnabled ? "enabled" : "disabled")+" debug logging", null);
response.sendRedirect("logviewer.jsp?log=debug"); response.sendRedirect("logviewer.jsp?log=debug");
...@@ -409,19 +408,18 @@ IFRAME { ...@@ -409,19 +408,18 @@ IFRAME {
<fmt:message key="logviewer.debug_log" />: &nbsp; <fmt:message key="logviewer.debug_log" />: &nbsp;
</td> </td>
<td width="1%"> <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>
<td width="1%" nowrap> <td width="1%" nowrap>
<label for="de01"><fmt:message key="logviewer.enabled" /></label> &nbsp; <label for="de01"><fmt:message key="logviewer.enabled" /></label> &nbsp;
</td> </td>
<td width="1%"> <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>
<td width="1%" nowrap> <td width="1%" nowrap>
<label for="de02">Disabled</label> &nbsp; <label for="de02">Disabled</label> &nbsp;
</td> </td>
<td width="1%"> <td width="1%">
<input type="hidden" name="wasDebugEnabled" value="<%= debugEnabled %>">
<input type="submit" name="" value="<fmt:message key="global.save_changes" />"> <input type="submit" name="" value="<fmt:message key="global.save_changes" />">
</td> </td>
<td width="94%">&nbsp;</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