1 package com
.intellij
.testFramework
;
3 import com
.intellij
.openapi
.application
.PathManager
;
4 import com
.intellij
.openapi
.diagnostic
.Logger
;
5 import com
.intellij
.openapi
.util
.io
.FileUtil
;
6 import com
.intellij
.openapi
.util
.text
.StringUtil
;
7 import org
.apache
.log4j
.LogManager
;
8 import org
.apache
.log4j
.xml
.DOMConfigurator
;
9 import org
.jetbrains
.annotations
.NonNls
;
12 import java
.io
.StringReader
;
14 @NonNls public class TestLoggerFactory
implements Logger
.Factory
{
15 private static final String SYSTEM_MACRO
= "$SYSTEM_DIR$";
16 private static final String APPLICATION_MACRO
= "$APPLICATION_DIR$";
17 private static final String LOGDIR_MACRO
= "$LOG_DIR$";
19 private boolean myInitialized
= false;
21 private static final TestLoggerFactory ourInstance
= new TestLoggerFactory();
22 public static final String LOG_DIR
= "testlog";
24 public static TestLoggerFactory
getInstance() {
28 private TestLoggerFactory() {
31 public Logger
getLoggerInstance(String name
) {
34 if (!isInitialized()) {
42 return new TestLogger(org
.apache
.log4j
.Logger
.getLogger(name
));
48 String fileName
= PathManager
.getBinPath() + File
.separator
+ "log.xml";
49 File logXmlFile
= new File(fileName
);
50 if (!logXmlFile
.exists()) {
53 System
.setProperty("log4j.defaultInitOverride", "true");
54 String text
= new String(FileUtil
.loadFileText(logXmlFile
));
55 String logDir
= PathManager
.getSystemPath() + "/" + LOG_DIR
;
56 text
= StringUtil
.replace(text
, SYSTEM_MACRO
, StringUtil
.replace(PathManager
.getSystemPath(), "\\", "\\\\"));
57 text
= StringUtil
.replace(text
, APPLICATION_MACRO
, StringUtil
.replace(PathManager
.getHomePath(), "\\", "\\\\"));
58 text
= StringUtil
.replace(text
, LOGDIR_MACRO
, StringUtil
.replace(logDir
, "\\", "\\\\"));
60 File file
= new File(PathManager
.getSystemPath() + File
.separator
+ LOG_DIR
);
63 DOMConfigurator domConfigurator
= new DOMConfigurator();
65 domConfigurator
.doConfigure(new StringReader(text
), LogManager
.getLoggerRepository());
67 catch (ClassCastException e
) {
69 System
.out
.println("log.xml content:\n" + text
);
79 private boolean isInitialized() {