From e0ce94ab7efd29f6a3aa5182648e3bdf3bba3de4 Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 2 Sep 2009 09:42:11 +0000 Subject: [PATCH] New settings method: return log file directory git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@687 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/Settings.java | 37 ++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/java/davmail/Settings.java b/src/java/davmail/Settings.java index 991d6ba2..7dbd3722 100644 --- a/src/java/davmail/Settings.java +++ b/src/java/davmail/Settings.java @@ -129,15 +129,44 @@ public class Settings { } /** - * Update Log4J config from settings. + * Return DavMail log file path + * @return full log file path */ - protected static void updateLoggingConfig() { - String logFilePath = Settings.getProperty("davmail.logFilePath"); + public static String getLogFilePath() { + String logFilePath = Settings.getProperty("davmail.logFilePath"); // use default log file path on Mac OS X - if ((logFilePath == null || logFilePath.length() == 0) + if ((logFilePath == null || logFilePath.length() == 0) && System.getProperty("os.name").toLowerCase().startsWith("mac os x")) { logFilePath = System.getProperty("user.home") + "/Library/Logs/DavMail/davmail.log"; } + return logFilePath; + } + + /** + * Return DavMail log file directory + * @return full log file directory + */ + public static String getLogFileDirectory() { + String logFilePath = getLogFilePath(); + if (logFilePath == null || logFilePath.length() == 0) { + return ""; + } + int lastSlashIndex = logFilePath.lastIndexOf('/'); + if (lastSlashIndex == -1) { + lastSlashIndex = logFilePath.lastIndexOf('\\'); + } + if (lastSlashIndex >= 0) { + return logFilePath.substring(0, lastSlashIndex); + } else { + return ""; + } + } + + /** + * Update Log4J config from settings. + */ + protected static void updateLoggingConfig() { + String logFilePath = getLogFilePath(); Logger rootLogger = Logger.getRootLogger(); try {