mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
Added a logFilePath setting to set log4j file appender path, this appender is now added dynamically to avoid davmail.log file create failure
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@593 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
c271617c12
commit
bcb690da7f
@ -44,33 +44,12 @@ public class DavGateway {
|
||||
Settings.setConfigFilePath(args[0]);
|
||||
}
|
||||
|
||||
updateLogFilePath();
|
||||
|
||||
Settings.load();
|
||||
DavGatewayTray.init();
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public static void updateLogFilePath() {
|
||||
// update log file path on Mac OS X
|
||||
if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
|
||||
String logFileDir = System.getProperty("user.home") + "/Library/Logs/DavMail";
|
||||
Logger rootLogger = Logger.getRootLogger();
|
||||
try {
|
||||
File file = new File(logFileDir);
|
||||
if (file.mkdirs()) {
|
||||
((FileAppender) rootLogger.getAppender("FileAppender")).setFile(logFileDir + "/davmail.log", true, false, 8192);
|
||||
} else {
|
||||
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_CREATE_LOG_FILE_DIR"));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_SET_LOG_FILE_PATH"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
// register custom SSL Socket factory
|
||||
DavGatewaySSLProtocolSocketFactory.register();
|
||||
|
@ -5,8 +5,7 @@ import davmail.ui.tray.DavGatewayTray;
|
||||
import java.util.Properties;
|
||||
import java.io.*;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.*;
|
||||
|
||||
/**
|
||||
* Settings facade
|
||||
@ -76,6 +75,7 @@ public class Settings {
|
||||
SETTINGS.put("log4j.logger.davmail", Level.DEBUG.toString());
|
||||
SETTINGS.put("log4j.logger.httpclient.wire", Level.WARN.toString());
|
||||
SETTINGS.put("log4j.logger.org.apache.commons.httpclient", Level.WARN.toString());
|
||||
SETTINGS.put("log4j.logFilePath", "");
|
||||
save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -89,12 +89,51 @@ public class Settings {
|
||||
}
|
||||
}
|
||||
}
|
||||
updateLoggingConfig();
|
||||
}
|
||||
|
||||
public static void updateLoggingConfig() {
|
||||
String logFilePath = Settings.getProperty("davmail.logFilePath");
|
||||
// use default log file path on Mac OS X
|
||||
if (logFilePath == null && System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
|
||||
logFilePath = System.getProperty("user.home") + "/Library/Logs/DavMail/davmail.log";
|
||||
}
|
||||
|
||||
Logger rootLogger = Logger.getRootLogger();
|
||||
try {
|
||||
if (logFilePath != null && logFilePath.length() > 0) {
|
||||
File logFile = new File(logFilePath);
|
||||
// create parent directory if needed
|
||||
File logFileDir = logFile.getParentFile();
|
||||
if (logFileDir != null && !logFileDir.exists()) {
|
||||
if (!logFileDir.mkdirs()) {
|
||||
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_CREATE_LOG_FILE_DIR"));
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logFilePath = "davmail.log";
|
||||
}
|
||||
// Build file appender
|
||||
RollingFileAppender fileAppender = ((RollingFileAppender) rootLogger.getAppender("FileAppender"));
|
||||
if (fileAppender == null) {
|
||||
fileAppender = new RollingFileAppender();
|
||||
fileAppender.setName("FileAppender");
|
||||
fileAppender.setMaxBackupIndex(2);
|
||||
fileAppender.setMaxFileSize("1MB");
|
||||
fileAppender.setLayout(new PatternLayout("%d{ISO8601} %-5p [%t] %c %x - %m%n"));
|
||||
}
|
||||
fileAppender.setFile(logFilePath, true, false, 8192);
|
||||
rootLogger.addAppender(fileAppender);
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_SET_LOG_FILE_PATH"));
|
||||
}
|
||||
|
||||
// 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"));
|
||||
|
||||
}
|
||||
|
||||
public static synchronized void save() {
|
||||
@ -113,6 +152,7 @@ public class Settings {
|
||||
}
|
||||
}
|
||||
}
|
||||
updateLoggingConfig();
|
||||
}
|
||||
|
||||
public static synchronized String getProperty(String property) {
|
||||
|
@ -55,6 +55,7 @@ public class SettingsFrame extends JFrame {
|
||||
JComboBox davmailLoggingLevelField;
|
||||
JComboBox httpclientLoggingLevelField;
|
||||
JComboBox wireLoggingLevelField;
|
||||
JTextField logFilePathField;
|
||||
|
||||
protected void addSettingComponent(JPanel panel, String label, JComponent component) {
|
||||
addSettingComponent(panel, label, component, null);
|
||||
@ -279,25 +280,37 @@ public class SettingsFrame extends JFrame {
|
||||
}
|
||||
|
||||
public JPanel getLoggingSettingsPanel() {
|
||||
JPanel loggingSettingsPanel = new JPanel(new GridLayout(4, 2));
|
||||
loggingSettingsPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_LOGGING_LEVELS")));
|
||||
JPanel loggingLevelPanel = new JPanel();
|
||||
JPanel leftLoggingPanel = new JPanel(new GridLayout(2, 2));
|
||||
JPanel rightLoggingPanel = new JPanel(new GridLayout(2, 2));
|
||||
loggingLevelPanel.add(leftLoggingPanel);
|
||||
loggingLevelPanel.add(rightLoggingPanel);
|
||||
|
||||
rootLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
davmailLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
httpclientLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
wireLoggingLevelField = new JComboBox(LOG_LEVELS);
|
||||
logFilePathField = new JTextField(Settings.getProperty("davmail.logFilePath"), 15);
|
||||
|
||||
rootLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("rootLogger"));
|
||||
davmailLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("davmail"));
|
||||
httpclientLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("org.apache.commons.httpclient"));
|
||||
wireLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient.wire"));
|
||||
|
||||
addSettingComponent(loggingSettingsPanel, BundleMessage.format("UI_LOG_DEFAULT"), rootLoggingLevelField);
|
||||
addSettingComponent(loggingSettingsPanel, BundleMessage.format("UI_LOG_DAVMAIL"), davmailLoggingLevelField);
|
||||
addSettingComponent(loggingSettingsPanel, BundleMessage.format("UI_LOG_HTTPCLIENT"), httpclientLoggingLevelField);
|
||||
addSettingComponent(loggingSettingsPanel, BundleMessage.format("UI_LOG_WIRE"), wireLoggingLevelField);
|
||||
addSettingComponent(leftLoggingPanel, BundleMessage.format("UI_LOG_DEFAULT"), rootLoggingLevelField);
|
||||
addSettingComponent(leftLoggingPanel, BundleMessage.format("UI_LOG_DAVMAIL"), davmailLoggingLevelField);
|
||||
addSettingComponent(rightLoggingPanel, BundleMessage.format("UI_LOG_HTTPCLIENT"), httpclientLoggingLevelField);
|
||||
addSettingComponent(rightLoggingPanel, BundleMessage.format("UI_LOG_WIRE"), wireLoggingLevelField);
|
||||
|
||||
return loggingSettingsPanel;
|
||||
JPanel logFilePathPanel = new JPanel();
|
||||
addSettingComponent(logFilePathPanel, BundleMessage.format("UI_LOG_FILE_PATH"), logFilePathField);
|
||||
|
||||
JPanel loggingPanel = new JPanel();
|
||||
loggingPanel.setLayout(new BoxLayout(loggingPanel, BoxLayout.Y_AXIS));
|
||||
loggingPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_LOGGING_LEVELS")));
|
||||
loggingPanel.add(logFilePathPanel);
|
||||
loggingPanel.add(loggingLevelPanel);
|
||||
return loggingPanel;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
@ -344,6 +357,7 @@ public class SettingsFrame extends JFrame {
|
||||
davmailLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("davmail"));
|
||||
httpclientLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("org.apache.commons.httpclient"));
|
||||
wireLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient.wire"));
|
||||
logFilePathField.setText(Settings.getProperty("davmail.logFilePath"));
|
||||
}
|
||||
|
||||
public SettingsFrame() {
|
||||
@ -431,6 +445,7 @@ public class SettingsFrame extends JFrame {
|
||||
Settings.setLoggingLevel("davmail", (Level) davmailLoggingLevelField.getSelectedItem());
|
||||
Settings.setLoggingLevel("org.apache.commons.httpclient", (Level) httpclientLoggingLevelField.getSelectedItem());
|
||||
Settings.setLoggingLevel("httpclient.wire", (Level) wireLoggingLevelField.getSelectedItem());
|
||||
Settings.setProperty("davmail.logFilePath", logFilePathField.getText());
|
||||
|
||||
dispose();
|
||||
Settings.save();
|
||||
|
@ -193,6 +193,7 @@ UI_LOG_DAVMAIL=DavMail:
|
||||
UI_LOG_DEFAULT=Default:
|
||||
UI_LOG_HTTPCLIENT=HttpClient:
|
||||
UI_LOG_WIRE=Wire:
|
||||
UI_LOG_FILE_PATH=Log file path:
|
||||
UI_NETWORK=Network
|
||||
UI_OWA_URL=OWA (Exchange) URL:
|
||||
UI_OWA_URL_HELP=Base Outlook Web Access URL
|
||||
|
@ -221,3 +221,4 @@ UI_PKCS11_LIBRARY=Librairie PKCS11
|
||||
UI_PKCS11_CONFIG_HELP=Configuration PKCS11 complémentaire optionnelle (slot, nssArgs, ...)
|
||||
UI_PKCS11_CONFIG=Configuration PKCS11
|
||||
UI_CLIENT_CERTIFICATE=Certificat client
|
||||
UI_LOG_FILE_PATH=Chemin du fichier de traces :
|
@ -1,5 +1,5 @@
|
||||
# Warning : actual log levels set in davmail.properties
|
||||
log4j.rootLogger=WARN, ConsoleAppender, FileAppender
|
||||
log4j.rootLogger=WARN, ConsoleAppender
|
||||
log4j.logger.davmail=DEBUG
|
||||
log4j.logger.httpclient.wire=WARN
|
||||
log4j.logger.org.apache.commons.httpclient=WARN
|
||||
@ -11,12 +11,3 @@ log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.ConsoleAppender.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c %x - %m%n
|
||||
|
||||
log4j.appender.FileAppender=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.FileAppender.maxBackupIndex=2
|
||||
log4j.appender.FileAppender.maxFileSize=1MB
|
||||
|
||||
# Path and name of log file
|
||||
log4j.appender.FileAppender.File=davmail.log
|
||||
# ConsoleAppender uses PatternLayout.
|
||||
log4j.appender.FileAppender.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.FileAppender.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c %x - %m%n
|
||||
|
@ -128,6 +128,13 @@
|
||||
</td>
|
||||
<td>WARN</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Log file Path</td>
|
||||
<td>DavMail log file path (default is davmail.log in working directory on Unix and Windows,
|
||||
~/Library/Logs/DavMail/davmail.log on OSX)
|
||||
</td>
|
||||
<td>davmail.log</td>
|
||||
</tr>
|
||||
</table>
|
||||
</p>
|
||||
<p>Uncheck a port to disable matching service.</p>
|
||||
|
@ -53,6 +53,7 @@ log4j.rootLogger=WARN
|
||||
log4j.logger.davmail=DEBUG
|
||||
log4j.logger.org.apache.commons.httpclient=WARN
|
||||
log4j.logger.httpclient.wire=WARN
|
||||
davmail.logFilePath=/var/log/davmail.log
|
||||
</source>
|
||||
<p>See
|
||||
<a href="gettingstarted.html">Getting started</a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user