mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-09 20:58:05 -05:00
From coverity: synchronize FileAppender creation
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2262 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
db626f8956
commit
93515d8ddb
@ -238,7 +238,6 @@ public final class Settings {
|
|||||||
public static void updateLoggingConfig() {
|
public static void updateLoggingConfig() {
|
||||||
String logFilePath = getLogFilePath();
|
String logFilePath = getLogFilePath();
|
||||||
|
|
||||||
Logger rootLogger = Logger.getRootLogger();
|
|
||||||
try {
|
try {
|
||||||
if (logFilePath != null && logFilePath.length() > 0) {
|
if (logFilePath != null && logFilePath.length() > 0) {
|
||||||
File logFile = new File(logFilePath);
|
File logFile = new File(logFilePath);
|
||||||
@ -253,31 +252,33 @@ public final class Settings {
|
|||||||
} else {
|
} else {
|
||||||
logFilePath = "davmail.log";
|
logFilePath = "davmail.log";
|
||||||
}
|
}
|
||||||
// Build file appender
|
synchronized (Logger.getRootLogger()) {
|
||||||
FileAppender fileAppender = (FileAppender) rootLogger.getAppender("FileAppender");
|
// Build file appender
|
||||||
if (fileAppender == null) {
|
FileAppender fileAppender = (FileAppender) Logger.getRootLogger().getAppender("FileAppender");
|
||||||
String logFileSize = Settings.getProperty("davmail.logFileSize");
|
if (fileAppender == null) {
|
||||||
if (logFileSize == null || logFileSize.length() == 0) {
|
String logFileSize = Settings.getProperty("davmail.logFileSize");
|
||||||
logFileSize = "1MB";
|
if (logFileSize == null || logFileSize.length() == 0) {
|
||||||
|
logFileSize = "1MB";
|
||||||
|
}
|
||||||
|
// set log file size to 0 to use an external rotation mechanism, e.g. logrotate
|
||||||
|
if ("0".equals(logFileSize)) {
|
||||||
|
fileAppender = new FileAppender();
|
||||||
|
} else {
|
||||||
|
fileAppender = new RollingFileAppender();
|
||||||
|
((RollingFileAppender) fileAppender).setMaxBackupIndex(2);
|
||||||
|
((RollingFileAppender) fileAppender).setMaxFileSize(logFileSize);
|
||||||
|
}
|
||||||
|
fileAppender.setName("FileAppender");
|
||||||
|
fileAppender.setEncoding("UTF-8");
|
||||||
|
fileAppender.setLayout(new PatternLayout("%d{ISO8601} %-5p [%t] %c %x - %m%n"));
|
||||||
}
|
}
|
||||||
// set log file size to 0 to use an external rotation mechanism, e.g. logrotate
|
fileAppender.setFile(logFilePath, true, false, 8192);
|
||||||
if ("0".equals(logFileSize)) {
|
Logger.getRootLogger().addAppender(fileAppender);
|
||||||
fileAppender = new FileAppender();
|
|
||||||
} else {
|
|
||||||
fileAppender = new RollingFileAppender();
|
|
||||||
((RollingFileAppender)fileAppender).setMaxBackupIndex(2);
|
|
||||||
((RollingFileAppender)fileAppender).setMaxFileSize(logFileSize);
|
|
||||||
}
|
|
||||||
fileAppender.setName("FileAppender");
|
|
||||||
fileAppender.setEncoding("UTF-8");
|
|
||||||
fileAppender.setLayout(new PatternLayout("%d{ISO8601} %-5p [%t] %c %x - %m%n"));
|
|
||||||
}
|
}
|
||||||
fileAppender.setFile(logFilePath, true, false, 8192);
|
|
||||||
rootLogger.addAppender(fileAppender);
|
|
||||||
|
|
||||||
// disable ConsoleAppender in gui mode
|
// disable ConsoleAppender in gui mode
|
||||||
if (!Settings.getBooleanProperty("davmail.server")) {
|
if (!Settings.getBooleanProperty("davmail.server")) {
|
||||||
ConsoleAppender consoleAppender = (ConsoleAppender) rootLogger.getAppender("ConsoleAppender");
|
ConsoleAppender consoleAppender = (ConsoleAppender) Logger.getRootLogger().getAppender("ConsoleAppender");
|
||||||
if (consoleAppender != null) {
|
if (consoleAppender != null) {
|
||||||
consoleAppender.setThreshold(Level.OFF);
|
consoleAppender.setThreshold(Level.OFF);
|
||||||
}
|
}
|
||||||
@ -474,7 +475,7 @@ public final class Settings {
|
|||||||
/**
|
/**
|
||||||
* Get all properties that are in the specified scope, that is, that start with '<scope>.'.
|
* Get all properties that are in the specified scope, that is, that start with '<scope>.'.
|
||||||
*
|
*
|
||||||
* @param scope start of property name
|
* @param scope start of property name
|
||||||
* @return properties
|
* @return properties
|
||||||
*/
|
*/
|
||||||
public static synchronized Properties getSubProperties(String scope) {
|
public static synchronized Properties getSubProperties(String scope) {
|
||||||
@ -488,9 +489,9 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
Properties result = new Properties();
|
Properties result = new Properties();
|
||||||
for (Map.Entry entry : SETTINGS.entrySet()) {
|
for (Map.Entry entry : SETTINGS.entrySet()) {
|
||||||
String key = (String)entry.getKey();
|
String key = (String) entry.getKey();
|
||||||
if (key.startsWith(keyStart)) {
|
if (key.startsWith(keyStart)) {
|
||||||
String value = (String)entry.getValue();
|
String value = (String) entry.getValue();
|
||||||
result.setProperty(key.substring(keyStart.length()), value);
|
result.setProperty(key.substring(keyStart.length()), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user