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
...@@ -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";
// TODO deprecate these properties
// JiveGlobals.getXMLProperty("log.debug.format"); // listen for changes to the log.debug.enabled property
// JiveGlobals.getXMLProperty("log.info.format"); static {
// JiveGlobals.getXMLProperty("log.warn.format"); PropertyEventDispatcher.addListener(new PropertyEventListener() {
// JiveGlobals.getXMLProperty("log.error.format");
// JiveGlobals.getXMLProperty("log.debug.size"); public void propertySet(String property, Map<String, Object> params) {
// JiveGlobals.getXMLProperty("log.info.size"); enableDebugLog(property, Boolean.parseBoolean(params.get("value").toString()));
// JiveGlobals.getXMLProperty("log.warn.size"); }
// JiveGlobals.getXMLProperty("log.error.size");
// JiveGlobals.getXMLProperty("log.debug.enabled"); 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);
}
}
});
}
/** /**
* @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