mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-06 03:08:02 -05:00
Added logging settings in davmail.properties and GUI (Support Request 2153851)
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@163 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
f6aa32ae64
commit
8844e3ab7b
@ -5,6 +5,9 @@ import davmail.tray.DavGatewayTray;
|
||||
import java.util.Properties;
|
||||
import java.io.*;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Settings facade
|
||||
*/
|
||||
@ -56,6 +59,12 @@ public class Settings {
|
||||
SETTINGS.put("davmail.proxyPassword", "");
|
||||
SETTINGS.put("davmail.server", "false");
|
||||
SETTINGS.put("davmail.server.certificate.hash", "");
|
||||
|
||||
// logging
|
||||
SETTINGS.put("log4j.rootLogger", "WARN");
|
||||
SETTINGS.put("log4j.logger.davmail", "DEBUG");
|
||||
SETTINGS.put("log4j.logger.httpclient.wire", "WARN");
|
||||
SETTINGS.put("log4j.logger.org.apache.commons.httpclient", "WARN");
|
||||
save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -69,6 +78,11 @@ public class Settings {
|
||||
}
|
||||
}
|
||||
}
|
||||
// update logging levels
|
||||
Settings.setLoggingLevel("rootLogger", Settings.getLoggingLevel("rootLogger"));
|
||||
Settings.setLoggingLevel("davmail", Settings.getLoggingLevel("davmail"));
|
||||
Settings.setLoggingLevel("httpclient.wire", Settings.getLoggingLevel("httpclient.wire"));
|
||||
Settings.setLoggingLevel("org.apache.commons.httpclient", Settings.getLoggingLevel("org.apache.commons.httpclient"));
|
||||
|
||||
}
|
||||
|
||||
@ -116,6 +130,39 @@ public class Settings {
|
||||
return "true".equals(propertyValue);
|
||||
}
|
||||
|
||||
protected static String getLoggingPrefix(String category) {
|
||||
String prefix;
|
||||
if ("rootLogger".equals(category)) {
|
||||
prefix = "log4j.";
|
||||
} else {
|
||||
prefix = "log4j.logger.";
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public static synchronized Level getLoggingLevel(String category) {
|
||||
String prefix = getLoggingPrefix(category);
|
||||
String currentValue = SETTINGS.getProperty(prefix + category);
|
||||
|
||||
if (currentValue != null && currentValue.length() > 0) {
|
||||
return Level.toLevel(currentValue);
|
||||
} else if ("rootLogger".equals(category)) {
|
||||
return Logger.getRootLogger().getLevel();
|
||||
} else {
|
||||
return Logger.getLogger(category).getLevel();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void setLoggingLevel(String category, Level level) {
|
||||
String prefix = getLoggingPrefix(category);
|
||||
SETTINGS.setProperty(prefix + category, level.toString());
|
||||
if ("rootLogger".equals(category)) {
|
||||
Logger.getRootLogger().setLevel(level);
|
||||
} else {
|
||||
Logger.getLogger(category).setLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void saveProperty(String property, String value) {
|
||||
Settings.load();
|
||||
Settings.setProperty(property, value);
|
||||
|
@ -1,18 +1,21 @@
|
||||
package davmail.ui;
|
||||
|
||||
import davmail.Settings;
|
||||
import davmail.DavGateway;
|
||||
import davmail.Settings;
|
||||
import davmail.tray.DavGatewayTray;
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* DavMail settings frame
|
||||
*/
|
||||
public class SettingsFrame extends JFrame {
|
||||
public static final Level[] LOG_LEVELS = {Level.OFF, Level.FATAL, Level.ERROR, Level.WARN, Level.INFO, Level.DEBUG, Level.ALL};
|
||||
|
||||
protected JTextField urlField;
|
||||
protected JTextField popPortField;
|
||||
protected JTextField smtpPortField;
|
||||
@ -28,6 +31,11 @@ public class SettingsFrame extends JFrame {
|
||||
JTextField bindAddressField;
|
||||
JTextField certHashField;
|
||||
|
||||
JComboBox rootLoggingLevelField;
|
||||
JComboBox davmailLoggingLevelField;
|
||||
JComboBox httpclientLoggingLevelField;
|
||||
JComboBox wireLoggingLevelField;
|
||||
|
||||
protected void addSettingComponent(JPanel panel, String label, Component component) {
|
||||
JLabel fieldLabel = new JLabel(label);
|
||||
fieldLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
@ -37,7 +45,7 @@ public class SettingsFrame extends JFrame {
|
||||
|
||||
protected JPanel getSettingsPanel() {
|
||||
JPanel settingsPanel = new JPanel(new GridLayout(4, 2));
|
||||
settingsPanel.setBorder(BorderFactory.createTitledBorder("Gateway settings"));
|
||||
settingsPanel.setBorder(BorderFactory.createTitledBorder("Gateway"));
|
||||
|
||||
urlField = new JTextField(Settings.getProperty("davmail.url"), 15);
|
||||
urlField.setToolTipText("Base outlook web access URL");
|
||||
@ -56,7 +64,7 @@ public class SettingsFrame extends JFrame {
|
||||
|
||||
protected JPanel getProxyPanel() {
|
||||
JPanel proxyPanel = new JPanel(new GridLayout(5, 2));
|
||||
proxyPanel.setBorder(BorderFactory.createTitledBorder("Proxy settings"));
|
||||
proxyPanel.setBorder(BorderFactory.createTitledBorder("Proxy"));
|
||||
|
||||
boolean enableProxy = Settings.getBooleanProperty("davmail.enableProxy");
|
||||
enableProxyField = new JCheckBox();
|
||||
@ -91,7 +99,7 @@ public class SettingsFrame extends JFrame {
|
||||
|
||||
public JPanel getNetworkSettingsPanel() {
|
||||
JPanel networkSettingsPanel = new JPanel(new GridLayout(3, 2));
|
||||
networkSettingsPanel.setBorder(BorderFactory.createTitledBorder("Network settings"));
|
||||
networkSettingsPanel.setBorder(BorderFactory.createTitledBorder("Network"));
|
||||
|
||||
allowRemoteField = new JCheckBox();
|
||||
allowRemoteField.setSelected(Settings.getBooleanProperty("davmail.allowRemote"));
|
||||
@ -109,6 +117,23 @@ public class SettingsFrame extends JFrame {
|
||||
return networkSettingsPanel;
|
||||
}
|
||||
|
||||
public JPanel getLoggingSettingsPanel() {
|
||||
JPanel loggingSettingsPanel = new JPanel(new GridLayout(4, 2));
|
||||
loggingSettingsPanel.setBorder(BorderFactory.createTitledBorder("Logging levels"));
|
||||
|
||||
rootLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
davmailLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
httpclientLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
wireLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
|
||||
addSettingComponent(loggingSettingsPanel, "Default: ", rootLoggingLevelField);
|
||||
addSettingComponent(loggingSettingsPanel, "DavMail: ", davmailLoggingLevelField);
|
||||
addSettingComponent(loggingSettingsPanel, "HttpClient: ", httpclientLoggingLevelField);
|
||||
addSettingComponent(loggingSettingsPanel, "Wire: ", wireLoggingLevelField);
|
||||
|
||||
return loggingSettingsPanel;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
// reload settings in form
|
||||
urlField.setText(Settings.getProperty("davmail.url"));
|
||||
@ -128,6 +153,11 @@ public class SettingsFrame extends JFrame {
|
||||
httpProxyUserField.setText(Settings.getProperty("davmail.proxyUser"));
|
||||
httpProxyPasswordField.setText(Settings.getProperty("davmail.proxyPassword"));
|
||||
certHashField.setText(Settings.getProperty("davmail.server.certificate.hash"));
|
||||
|
||||
rootLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("rootLogger"));
|
||||
davmailLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("davmail"));
|
||||
httpclientLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("org.apache.commons.httpclient"));
|
||||
wireLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient.wire"));
|
||||
}
|
||||
|
||||
public SettingsFrame() {
|
||||
@ -137,16 +167,20 @@ public class SettingsFrame extends JFrame {
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane();
|
||||
|
||||
JPanel mainPanel = new JPanel(new GridLayout(2, 1));
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
mainPanel.add(getSettingsPanel());
|
||||
mainPanel.add(getProxyPanel());
|
||||
mainPanel.add(Box.createVerticalGlue());
|
||||
|
||||
tabbedPane.add("Main", mainPanel);
|
||||
|
||||
JPanel advancedPanel = new JPanel();
|
||||
advancedPanel.setLayout(new BorderLayout());
|
||||
advancedPanel.setLayout(new BoxLayout(advancedPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
advancedPanel.add("North", getNetworkSettingsPanel());
|
||||
advancedPanel.add(getNetworkSettingsPanel());
|
||||
advancedPanel.add(getLoggingSettingsPanel());
|
||||
advancedPanel.add(Box.createVerticalGlue());
|
||||
|
||||
tabbedPane.add("Advanced", advancedPanel);
|
||||
|
||||
@ -170,6 +204,12 @@ public class SettingsFrame extends JFrame {
|
||||
Settings.setProperty("davmail.proxyUser", httpProxyUserField.getText());
|
||||
Settings.setProperty("davmail.proxyPassword", httpProxyPasswordField.getText());
|
||||
Settings.setProperty("davmail.server.certificate.hash", certHashField.getText());
|
||||
|
||||
Settings.setLoggingLevel("rootLogger", (Level) rootLoggingLevelField.getSelectedItem());
|
||||
Settings.setLoggingLevel("davmail", (Level) davmailLoggingLevelField.getSelectedItem());
|
||||
Settings.setLoggingLevel("org.apache.commons.httpclient", (Level) httpclientLoggingLevelField.getSelectedItem());
|
||||
Settings.setLoggingLevel("httpclient.wire", (Level) wireLoggingLevelField.getSelectedItem());
|
||||
|
||||
dispose();
|
||||
Settings.save();
|
||||
// restart listeners with new config
|
||||
|
@ -1,8 +1,8 @@
|
||||
# Set root logger level to DEBUG and its only appender to ConsoleAppender.
|
||||
log4j.rootLogger=DEBUG, ConsoleAppender, FileAppender
|
||||
|
||||
log4j.logger.httpclient.wire=WARN, ConsoleAppender
|
||||
log4j.logger.org.apache.commons.httpclient=WARN, ConsoleAppender
|
||||
# Warning : actual log levels set in davmail.properties
|
||||
log4j.rootLogger=WARN, ConsoleAppender, FileAppender
|
||||
log4j.logger.davmail=DEBUG
|
||||
log4j.logger.httpclient.wire=WARN
|
||||
log4j.logger.org.apache.commons.httpclient=WARN
|
||||
|
||||
# ConsoleAppender is set to be a ConsoleAppender.
|
||||
log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
|
||||
|
@ -61,6 +61,11 @@
|
||||
a manually accepted certificate (invalid or self signed)</td>
|
||||
<td>9F:CC:59:82:1F:C:CD:29:7C:70:F0:D8:37:B1:77:3F:48:84:AE:C4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Logging levels</td>
|
||||
<td>Default, DavMail and HttpClient logging levels, see Log4J documentation for more details</td>
|
||||
<td>WARN</td>
|
||||
</tr>
|
||||
</table>
|
||||
</p>
|
||||
<p>The bottom panel can be activated to set an HTTP proxy and associated credentials if needed</p>
|
||||
|
@ -41,6 +41,10 @@ davmail.proxyPassword=
|
||||
davmail.server=true
|
||||
davmail.bindAddress=
|
||||
davmail.server.certificate.hash=
|
||||
log4j.rootLogger=WARN
|
||||
log4j.logger.davmail=DEBUG
|
||||
log4j.logger.org.apache.commons.httpclient=WARN
|
||||
log4j.logger.httpclient.wire=WARN
|
||||
</source>
|
||||
<p>See
|
||||
<a href="gettingstarted.html">Getting started</a>
|
||||
|
Loading…
Reference in New Issue
Block a user