<commit_before>package com.intellij.testFramework;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.apache.log4j.LogManager;
import org.apache.log4j.xml.DOMConfigurator;
import org.jetbrains.annotations.NonNls;

import java.io.File;
import java.io.StringReader;

@NonNls public class TestLoggerFactory implements Logger.Factory {
  private static final String SYSTEM_MACRO = "$SYSTEM_DIR$";
  private static final String APPLICATION_MACRO = "$APPLICATION_DIR$";
  private static final String LOGDIR_MACRO = "$LOG_DIR$";

  private boolean myInitialized = false;

  private static final TestLoggerFactory ourInstance = new TestLoggerFactory();
  public static final String LOG_DIR = "testlog";

  public static TestLoggerFactory getInstance() {
    return ourInstance;
  }

  private TestLoggerFactory() {
  }

  public Logger getLoggerInstance(String name) {
    synchronized (this) {
      try {
        if (!isInitialized()) {
          init();
        }
      }
      catch (Exception e) {
        e.printStackTrace();
      }

      return new TestLogger(org.apache.log4j.Logger.getLogger(name));
    }
  }

  private void init() {
    try {
      String fileName = PathManager.getBinPath() + File.separator + "log.xml";
      File logXmlFile = new File(fileName);
      if (!logXmlFile.exists()) {
        return;
      }
      System.setProperty("log4j.defaultInitOverride", "true");
      String text = new String(FileUtil.loadFileText(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(LOG_DIR, "\\", "\\\\"));

      File file = new File(PathManager.getSystemPath() + File.separator + LOG_DIR);
      file.mkdirs();

      DOMConfigurator domConfigurator = new DOMConfigurator();
      try {
        domConfigurator.doConfigure(new StringReader(text), LogManager.getLoggerRepository());
      }
      catch (ClassCastException e) {
        // shit :-E
        System.out.println("log.xml content:\n" + text);<commit_msg>fix setting LOG_DIR for tests<commit_after>package com.intellij.testFramework;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.apache.log4j.LogManager;
import org.apache.log4j.xml.DOMConfigurator;
import org.jetbrains.annotations.NonNls;

import java.io.File;
import java.io.StringReader;

@NonNls public class TestLoggerFactory implements Logger.Factory {
  private static final String SYSTEM_MACRO = "$SYSTEM_DIR$";
  private static final String APPLICATION_MACRO = "$APPLICATION_DIR$";
  private static final String LOGDIR_MACRO = "$LOG_DIR$";

  private boolean myInitialized = false;

  private static final TestLoggerFactory ourInstance = new TestLoggerFactory();
  public static final String LOG_DIR = "testlog";

  public static TestLoggerFactory getInstance() {
    return ourInstance;
  }

  private TestLoggerFactory() {
  }

  public Logger getLoggerInstance(String name) {
    synchronized (this) {
      try {
        if (!isInitialized()) {
          init();
        }
      }
      catch (Exception e) {
        e.printStackTrace();
      }

      return new TestLogger(org.apache.log4j.Logger.getLogger(name));
    }
  }

  private void init() {
    try {
      String fileName = PathManager.getBinPath() + File.separator + "log.xml";
      File logXmlFile = new File(fileName);
      if (!logXmlFile.exists()) {
        return;
      }
      System.setProperty("log4j.defaultInitOverride", "true");
      String text = new String(FileUtil.loadFileText(logXmlFile));
      String logDir = PathManager.getSystemPath() + "/" + LOG_DIR;
      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(logDir, "\\", "\\\\"));

      File file = new File(PathManager.getSystemPath() + File.separator + LOG_DIR);
      file.mkdirs();

      DOMConfigurator domConfigurator = new DOMConfigurator();
      try {
        domConfigurator.doConfigure(new StringReader(text), LogManager.getLoggerRepository());
      }
      catch (ClassCastException e) {
        // shit :-E
        System.out.println("log.xml content:\n" + text);
{'fraction_non_alphanumeric': 0.12260216847372811, 'fraction_numerical': 0.0016680567139282735, 'mean_word_length': 3.5642245480494767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2772244', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1408, 'n_words': 293}