This commit is contained in:
Roman Shevchenko
2012-06-09 19:37:50 +04:00
parent 335692cd37
commit cae534e044
2 changed files with 26 additions and 78 deletions
+5 -14
View File
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CONSOLE-WARN" class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.err"/>
@@ -29,9 +29,9 @@
</appender>
<appender name="DIALOG" class="com.intellij.diagnostic.DialogAppender">
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="INFO"/>
</filter>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="INFO"/>
</filter>
</appender>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
@@ -52,19 +52,10 @@
</layout>
</appender>
<!-- <category name="#com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier">
<level value="DEBUG"/>
<appender-ref ref="FILE"/>
</category>
<category name="#com.intellij.openapi.diff.impl.patch.apply.ApplyFilePatchBase">
<level value="DEBUG"/>
<appender-ref ref="FILE"/>
</category> -->
<root>
<priority value="INFO"/>
<appender-ref ref="DIALOG"/>
<appender-ref ref="CONSOLE-WARN"/> <!-- $COMMENT_LINE_FOR_TEST_MODE$ If a line contains such macro, it will be deleted then we start IDEA in JUnit Test mode -->
<appender-ref ref="CONSOLE-WARN"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,53 +25,42 @@ import org.apache.log4j.xml.DOMConfigurator;
import java.io.File;
import java.io.StringReader;
@SuppressWarnings({"HardCodedStringLiteral"})
@SuppressWarnings({"CallToPrintStackTrace", "UseOfSystemOutOrSystemErr"})
public class LoggerFactory implements Logger.Factory {
private static final String SYSTEM_MACRO = "$SYSTEM_DIR$";
private static final String APPLICATION_MACRO = "$APPLICATION_DIR$";
private static final String COMMENT_LINE_FOR_TEST_MODE_MACRO = "$COMMENT_LINE_FOR_TEST_MODE$";
private static final String LOGDIR_MACRO = "$LOG_DIR$";
private static final String LOG_DIR_MACRO = "$LOG_DIR$";
private boolean myInitialized = false;
private static final LoggerFactory ourInstance = new LoggerFactory();
public static final String LOG_DIR = "log";
public static LoggerFactory getInstance() {
return ourInstance;
}
private LoggerFactory() {
}
private LoggerFactory() { }
public Logger getLoggerInstance(String name) {
synchronized (this) {
try {
if (!isInitialized()) {
init();
}
@Override
public synchronized Logger getLoggerInstance(String name) {
try {
if (!myInitialized) {
init();
}
catch (Exception e) {
e.printStackTrace();
}
return new IdeaLogger(org.apache.log4j.Logger.getLogger(name));
}
catch (Exception e) {
e.printStackTrace();
}
return new IdeaLogger(org.apache.log4j.Logger.getLogger(name));
}
private void init() {
try {
/*
//debug code. Don't delete.
ClassLoader classLoader = Logger.class.getClassLoader();
if (!(classLoader.getClass().getName().startsWith("com.intellij"))) {
System.err.println("Logger shouldn't be used outside the PluginManager");
Thread.dumpStack();
}
*/
System.setProperty("log4j.defaultInitOverride", "true");
File logXmlFile = FileUtil.findFirstThatExist(PathManager.getHomePath() + "/bin/log.xml", PathManager.getHomePath() + "/community/bin/log.xml");
File logXmlFile = FileUtil.findFirstThatExist(PathManager.getHomePath() + "/bin/log.xml",
PathManager.getHomePath() + "/community/bin/log.xml");
if (logXmlFile == null) {
throw new RuntimeException("log.xml file does not exist! Path: [ $home/bin/log.xml]");
}
@@ -79,14 +68,12 @@ public class LoggerFactory implements Logger.Factory {
String text = FileUtil.loadFile(logXmlFile);
text = StringUtil.replace(text, SYSTEM_MACRO, StringUtil.replace(PathManager.getSystemPath(), "\\", "\\\\"));
text = StringUtil.replace(text, APPLICATION_MACRO, StringUtil.replace(PathManager.getHomePath(), "\\", "\\\\"));
text = StringUtil.replace(text, LOGDIR_MACRO, StringUtil.replace(PathManager.getLogPath(), "\\", "\\\\"));
if ("true".equals(System.getProperty("idea.test.test_mode"))) {
text = commentTestModeLines(text);
}
text = StringUtil.replace(text, LOG_DIR_MACRO, StringUtil.replace(PathManager.getLogPath(), "\\", "\\\\"));
File file = new File(PathManager.getLogPath());
file.mkdirs();
if (!file.mkdirs() && !file.exists()) {
System.err.println("Cannot create log directory: " + file);
}
new DOMConfigurator().doConfigure(new StringReader(text), LogManager.getLoggerRepository());
@@ -96,34 +83,4 @@ public class LoggerFactory implements Logger.Factory {
e.printStackTrace();
}
}
private boolean isInitialized() {
return myInitialized;
}
private static String commentTestModeLines(String text) {
String result = text;
int index = text.indexOf(COMMENT_LINE_FOR_TEST_MODE_MACRO);
if (index != -1) {
String str1 = result.substring(0, index);
String str2 = result.substring(index);
int firstLineChar = Math.max(str1.lastIndexOf('\n'), str1.lastIndexOf('\r'));
int lastLineChar = str2.indexOf('\n');
int lastLineChar2 = str2.indexOf('\r');
if (lastLineChar == -1) {
lastLineChar = lastLineChar2;
}
else if (lastLineChar2 != -1) {
lastLineChar = Math.min(lastLineChar, lastLineChar2);
}
if (firstLineChar != -1) {
str1 = str1.substring(0, firstLineChar);
}
if (lastLineChar != -1) {
str2 = str2.substring(lastLineChar);
}
result = commentTestModeLines(str1) + commentTestModeLines(str2);
}
return result;
}
}