org.apache.log4j.xml.DOMConfigurator Java Examples

The following examples show how to use org.apache.log4j.xml.DOMConfigurator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XLoggerTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
void common(int number) throws Exception {
  DOMConfigurator.configure("input/xml/customLogger"+number+".xml");

  int i = -1;
  Logger root = Logger.getRootLogger();

  logger.trace("Message " + ++i);
  logger.debug("Message " + ++i);
  logger.warn ("Message " + ++i);
  logger.error("Message " + ++i);
  logger.fatal("Message " + ++i);
  Exception e = new Exception("Just testing");
  logger.debug("Message " + ++i, e);

  Transformer.transform(
    "output/temp", FILTERED,
    new Filter[] {
      new LineNumberFilter(), new SunReflectFilter(),
      new JunitTestRunnerFilter()
    });
  assertTrue(Compare.compare(FILTERED, "witness/customLogger."+number));

}
 
Example #2
Source File: Launcher.java    From CapturePacket with MIT License 6 votes vote down vote up
public static void main(final String... args) {
    File log4jConfigurationFile = new File(
            "src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    try {
        final int port = 9090;

        System.out.println("About to start server on port: " + port);
        HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
                .bootstrapFromFile("./littleproxy.properties")
                .withPort(port).withAllowLocalOnly(false);

        bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager());

        System.out.println("About to start...");
        bootstrap.start();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        System.exit(1);
    }
}
 
Example #3
Source File: SampleManagementServerApp.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
private static void setupLog4j() {
    URL configUrl = System.class.getResource("/resources/log4j-cloud.xml");
    if (configUrl != null) {
        System.out.println("Configure log4j using log4j-cloud.xml");

        try {
            File file = new File(configUrl.toURI());

            System.out.println("Log4j configuration from : " + file.getAbsolutePath());
            DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000);
        } catch (URISyntaxException e) {
            System.out.println("Unable to convert log4j configuration Url to URI");
        }
    } else {
        System.out.println("Configure log4j with default properties");
    }
}
 
Example #4
Source File: PostgresqlDAOTest.java    From sync-service with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void testSetup() throws IOException, SQLException, DAOConfigurationException {

	URL configFileResource = PostgresqlDAOTest.class.getResource("/com/ast/processserver/resources/log4j.xml");
	DOMConfigurator.configure(configFileResource);

	Config.loadProperties();

	String dataSource = "postgresql";
	DAOFactory factory = new DAOFactory(dataSource);
	connection = ConnectionPoolFactory.getConnectionPool(dataSource).getConnection();
	workspaceDAO = factory.getWorkspaceDao(connection);
	userDao = factory.getUserDao(connection);
	objectDao = factory.getItemDAO(connection);
	oversionDao = factory.getItemVersionDAO(connection);
}
 
Example #5
Source File: Log4jTest.java    From sofa-common-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocalProperties() throws NoSuchFieldException, IllegalAccessException {

    LoggerRepository repo2 = new Hierarchy(new RootLogger((Level) Level.DEBUG));
    URL url2 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/log4j/log4j_b.xml");
    DOMConfigurator domConfigurator = new DOMConfigurator();

    Field field = DOMConfigurator.class.getDeclaredField("props");
    field.setAccessible(true);
    Properties props = new Properties();
    field.set(domConfigurator, props);
    props.put("hello", "defaultb");

    domConfigurator.doConfigure(url2, repo2);

    Logger logger2 = repo2.getLogger("com.foo.Bar3");
    Assert.assertTrue(logger2.getAllAppenders().hasMoreElements());

}
 
Example #6
Source File: Log4jEnabledTestCase.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() {
    URL configUrl = System.class.getResource("/conf/log4j-cloud.xml");
    if (configUrl != null) {
        System.out.println("Configure log4j using log4j-cloud.xml");

        try {
            File file = new File(configUrl.toURI());

            System.out.println("Log4j configuration from : " + file.getAbsolutePath());
            DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000);
        } catch (URISyntaxException e) {
            System.out.println("Unable to convert log4j configuration Url to URI");
        }
    } else {
        System.out.println("Configure log4j with default properties");
    }
}
 
Example #7
Source File: GreenMailStandaloneRunner.java    From greenmail with Apache License 2.0 6 votes vote down vote up
protected static void configureLogging(Properties properties) {
    // Init logging: Try standard log4j configuration mechanism before falling back to
    // provided logging configuration
    String log4jConfig = System.getProperty("log4j.configuration");
    if (null == log4jConfig) {
        if (properties.containsKey(PropertiesBasedServerSetupBuilder.GREENMAIL_VERBOSE)) {
            DOMConfigurator.configure(GreenMailStandaloneRunner.class.getResource("/log4j-verbose.xml"));
        } else {
            DOMConfigurator.configure(GreenMailStandaloneRunner.class.getResource("/log4j.xml"));
        }
    } else {
        if (log4jConfig.toLowerCase().endsWith(".xml")) {
            DOMConfigurator.configure(log4jConfig);
        } else {
            PropertyConfigurator.configure(log4jConfig);
        }
    }
}
 
Example #8
Source File: TableAdmin.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
private void reloadConfig() throws MalformedURLException, FactoryConfigurationError, BException {
  String blurHome = System.getenv("BLUR_HOME");
  if (blurHome != null) {
    File blurHomeFile = new File(blurHome);
    if (blurHomeFile.exists()) {
      File log4jFile = new File(new File(blurHomeFile, "conf"), "log4j.xml");
      if (log4jFile.exists()) {
        LOG.info("Reseting log4j config from [{0}]", log4jFile);
        LogManager.resetConfiguration();
        DOMConfigurator.configure(log4jFile.toURI().toURL());
        return;
      }
    }
  }
  URL url = TableAdmin.class.getResource("/log4j.xml");
  if (url != null) {
    LOG.info("Reseting log4j config from classpath resource [{0}]", url);
    LogManager.resetConfiguration();
    DOMConfigurator.configure(url);
    return;
  }
  throw new BException("Could not locate log4j file to reload, doing nothing.");
}
 
Example #9
Source File: Launcher.java    From LittleProxy-mitm with Apache License 2.0 6 votes vote down vote up
public static void main(final String... args) {
    File log4jConfigurationFile = new File(
            "src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    try {
        final int port = 9090;

        System.out.println("About to start server on port: " + port);
        HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
                .bootstrapFromFile("./littleproxy.properties")
                .withPort(port).withAllowLocalOnly(false);

        bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager());

        System.out.println("About to start...");
        bootstrap.start();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        System.exit(1);
    }
}
 
Example #10
Source File: MergeTool.java    From rya with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final String log4jConfiguration = System.getProperties().getProperty("log4j.configuration");
    if (StringUtils.isNotBlank(log4jConfiguration)) {
        final String parsedConfiguration = PathUtils.clean(StringUtils.removeStart(log4jConfiguration, "file:"));
        final File configFile = new File(parsedConfiguration);
        if (configFile.exists()) {
            DOMConfigurator.configure(parsedConfiguration);
        } else {
            BasicConfigurator.configure();
        }
    }
    log.info("Starting Merge Tool");

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            log.error("Uncaught exception in " + thread.getName(), throwable);
        }
    });

    final int returnCode = setupAndRun(args);

    log.info("Finished running Merge Tool");

    System.exit(returnCode);
}
 
Example #11
Source File: GridTestLog4jLogger.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new logger with given configuration {@code cfgUrl}.
 *
 * @param cfgUrl URL for Log4j configuration XML file.
 * @throws IgniteCheckedException Thrown in case logger can't be created.
 */
public GridTestLog4jLogger(final URL cfgUrl) throws IgniteCheckedException {
    if (cfgUrl == null)
        throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");

    cfg = cfgUrl.getPath();

    addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
        @Override public Logger apply(Boolean init) {
            if (init)
                DOMConfigurator.configure(cfgUrl);

            return Logger.getRootLogger();
        }
    });

    quiet = quiet0;
}
 
Example #12
Source File: Log4jLogging.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void applyLog4jConfiguration() {
  LogLog.setQuietMode( true );
  LogManager.resetConfiguration();
  LogLog.setQuietMode( false );

  /**
   * On DOMConfigurator.doConfigure() no exception is ever propagated; it's caught and its stacktrace is written to System.err.
   *
   * @link https://github.com/apache/log4j/blob/v1_2_17_rc3/src/main/java/org/apache/log4j/xml/DOMConfigurator.java#L877-L878
   *
   * When the kettle5-log4j-plugin is dropped under ~/.kettle/plugins ( which is also a valid location for classic pdi plugins )
   * we get a System.err 'FileNotFoundException' stacktrace, as this is attempting to fetch the log4j.xml under a (default path) of
   * data-integration/plugins/kettle5-log4j-plugin; but in this scenario ( again, a valid one ), kettle5-log4j-plugin is under ~/.kettle/plugins
   *
   * With the inability to catch any exception ( as none is ever propagated ), the option left is to infer the starting path of this plugin's jar;
   * - If it starts with Const.getKettleDirectory(): then we know it to have been dropped in ~/.kettle/plugins ( a.k.a. Const.getKettleDirectory() )
   * - Otherwise: fallback to default/standard location, which is under <pdi-install-dir>/</>data-integration/plugins
   */
  final String log4jPath = getPluginPath().startsWith( getKettleDirPath() )
      ? ( Const.getKettleDirectory() + File.separator + PLUGIN_PROPERTIES_FILE ) : getConfigurationFileName();

  DOMConfigurator.configure( log4jPath );
}
 
Example #13
Source File: ErrorHandlerTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void test1() throws Exception {
  DOMConfigurator.configure("input/xml/fallback1.xml");
  common();

  ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT, 
			       EXCEPTION1, EXCEPTION2, EXCEPTION3});

  ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT, 
			       EXCEPTION1, EXCEPTION2, EXCEPTION3});

  Transformer.transform(TEMP_A1, FILTERED_A1, new Filter[] {cf1, 
					new LineNumberFilter()});

  Transformer.transform(TEMP_A2, FILTERED_A2, new Filter[] {cf2,
                                    new LineNumberFilter(), new ISO8601Filter()});

  assertTrue(Compare.compare(FILTERED_A1, "witness/dom.A1.1"));
  assertTrue(Compare.compare(FILTERED_A2, "witness/dom.A2.1"));
}
 
Example #14
Source File: Launcher.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
public static void main(final String... args) {
    File log4jConfigurationFile = new File(
            "src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    try {
        final int port = 9090;

        System.out.println("About to start server on port: " + port);
        HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
                .bootstrapFromFile("./littleproxy.properties")
                .withPort(port).withAllowLocalOnly(false);

        bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager());

        System.out.println("About to start...");
        bootstrap.start();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        System.exit(1);
    }
}
 
Example #15
Source File: Log4JLogger.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new logger with given configuration {@code cfgUrl}.
 * <p>
 * If {@code watchDelay} is not zero, created logger will check the configuration file for changes once every
 * {@code watchDelay} milliseconds, and update its configuration if the file was changed.
 * See {@link DOMConfigurator#configureAndWatch(String, long)} for details.
 *
 * @param cfgUrl URL for Log4j configuration XML file.
 * @param watchDelay delay in milliseconds used to check configuration file for changes.
 * @throws IgniteCheckedException Thrown in case logger can't be created.
 */
public Log4JLogger(final URL cfgUrl, final long watchDelay) throws IgniteCheckedException {
    if (cfgUrl == null)
        throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");

    if (watchDelay < 0)
        throw new IgniteCheckedException("watchDelay can't be negative: " + watchDelay);

    cfg = cfgUrl.getPath();

    addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
        @Override public Logger apply(Boolean init) {
            if (init) {
                if (watchDelay > 0)
                    DOMConfigurator.configureAndWatch(cfg, watchDelay);
                else
                    DOMConfigurator.configure(cfg);
            }

            return Logger.getRootLogger();
        }
    });

    quiet = quiet0;
}
 
Example #16
Source File: GridTestLog4jLogger.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new logger with given configuration {@code path}.
 *
 * @param path Path to log4j configuration XML file.
 * @throws IgniteCheckedException Thrown in case logger can't be created.
 */
public GridTestLog4jLogger(String path) throws IgniteCheckedException {
    if (path == null)
        throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");

    this.cfg = path;

    final URL cfgUrl = U.resolveIgniteUrl(path);

    if (cfgUrl == null)
        throw new IgniteCheckedException("Log4j configuration path was not found: " + path);

    addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
        @Override public Logger apply(Boolean init) {
            if (init)
                DOMConfigurator.configure(cfgUrl);

            return Logger.getRootLogger();
        }
    });

    quiet = quiet0;
}
 
Example #17
Source File: AlbianLoggerService.java    From Albianj2 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void loading() throws AlbianServiceException {
    try {
        Thread.currentThread().setContextClassLoader(AlbianClassLoader.getInstance());
        if (KernelSetting.getAlbianConfigFilePath().startsWith("http://")) {
            DOMConfigurator.configure(new URL(Path
                    .getExtendResourcePath(KernelSetting
                            .getAlbianConfigFilePath() + "log4j.xml")));
        } else {

            DOMConfigurator.configure(Path
                    .getExtendResourcePath(KernelSetting
                            .getAlbianConfigFilePath() + "log4j.xml"));
        }

        super.loading();
        loggers = new ConcurrentHashMap<String, Logger>();
    } catch (Exception exc) {
        throw new AlbianServiceException(exc.getMessage(), exc.getCause());
    }
}
 
Example #18
Source File: GridTestLog4jLogger.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new logger with given configuration {@code cfgFile}.
 *
 * @param cfgFile Log4j configuration XML file.
 * @throws IgniteCheckedException Thrown in case logger can't be created.
 */
public GridTestLog4jLogger(File cfgFile) throws IgniteCheckedException {
    if (cfgFile == null)
        throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");

    if (!cfgFile.exists() || cfgFile.isDirectory())
        throw new IgniteCheckedException("Log4j configuration path was not found or is a directory: " + cfgFile);

    cfg = cfgFile.getAbsolutePath();

    addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
        @Override public Logger apply(Boolean init) {
            if (init)
                DOMConfigurator.configure(cfg);

            return Logger.getRootLogger();
        }
    });

    quiet = quiet0;
}
 
Example #19
Source File: CopyTool.java    From rya with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final String log4jConfiguration = System.getProperties().getProperty("log4j.configuration");
    if (StringUtils.isNotBlank(log4jConfiguration)) {
        final String parsedConfiguration = PathUtils.clean(StringUtils.removeStart(log4jConfiguration, "file:"));
        final File configFile = new File(parsedConfiguration);
        if (configFile.exists()) {
            DOMConfigurator.configure(parsedConfiguration);
        } else {
            BasicConfigurator.configure();
        }
    }
    log.info("Starting Copy Tool");

    Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> log.error("Uncaught exception in " + thread.getName(), throwable));

    final CopyTool copyTool = new CopyTool();
    final int returnCode = copyTool.setupAndRun(args);

    log.info("Finished running Copy Tool");

    System.exit(returnCode);
}
 
Example #20
Source File: ZigBeeConsoleJavaSE.java    From zigbee4java with Apache License 2.0 5 votes vote down vote up
/**
    * The main method.
    * @param args the command arguments
    */
public static void main(final String[] args) {
	DOMConfigurator.configure("./log4j.xml");

	final String serialPortName;
	final int channel;
	final int pan;
	final boolean resetNetwork;

	try {
		serialPortName = args[0];
		channel        = Integer.parseInt(args[1]);
		pan            = parseDecimalOrHexInt(args[2]);			
		resetNetwork   = args[3].equals("true");

	} catch (final Throwable t) {
           t.printStackTrace();
		System.out.println(USAGE);
		return;
	}

	final SerialPort serialPort = new SerialPortImpl(serialPortName, DEFAULT_BAUD_RATE);
	final ZigBeeConsole console = new ZigBeeConsole(serialPort,pan,channel,resetNetwork);

       console.start();

}
 
Example #21
Source File: SocketAppenderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void setUp() {
    DOMConfigurator.configure("input/xml/SocketAppenderTestConfig.xml");

    logger = Logger.getLogger(SocketAppenderTest.class);
    primary = logger.getAppender("remote");
    secondary = (LastOnlyAppender) Logger.getLogger(
            "org.apache.log4j.net.SocketAppenderTestDummy").getAppender("lastOnly");
}
 
Example #22
Source File: LogConfig.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public void enableSimplifiedLogging() {
    if (simpleLoggingConfigured.get()) {
        return;
    }

    simpleLoggingConfigured.set(true);
    DefaultMmLogger.getInstance().setLogLevel(CAT_MEGAMEK,
                                              LogLevel.INFO);

    // Check for updated logging properties every 30 seconds.
    DOMConfigurator.configureAndWatch(LOG_CONFIG_FILE_PATH, 30000);
}
 
Example #23
Source File: Log4JLogger.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new logger with given configuration {@code path}.
 * <p>
 * If {@code watchDelay} is not zero, created logger will check the configuration file for changes once every
 * {@code watchDelay} milliseconds, and update its configuration if the file was changed.
 * See {@link DOMConfigurator#configureAndWatch(String, long)} for details.
 *
 * @param path Path to log4j configuration XML file.
 * @param watchDelay delay in milliseconds used to check configuration file for changes.
 * @throws IgniteCheckedException Thrown in case logger can't be created.
 */
public Log4JLogger(final String path, long watchDelay) throws IgniteCheckedException {
    if (path == null)
        throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");

    if (watchDelay < 0)
        throw new IgniteCheckedException("watchDelay can't be negative: " + watchDelay);

    this.cfg = path;

    final File cfgFile = U.resolveIgnitePath(path);

    if (cfgFile == null)
        throw new IgniteCheckedException("Log4j configuration path was not found: " + path);

    addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
        @Override public Logger apply(Boolean init) {
            if (init) {
                if (watchDelay > 0)
                    DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay);
                else
                    DOMConfigurator.configure(cfgFile.getPath());
            }

            return Logger.getRootLogger();
        }
    });

    quiet = quiet0;
}
 
Example #24
Source File: SMTPAppenderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
   * Tests that triggeringPolicy element will set evaluator.
   */
public void testTrigger() {
    DOMConfigurator.configure("input/xml/smtpAppender1.xml");
    SMTPAppender appender = (SMTPAppender) Logger.getRootLogger().getAppender("A1");
    TriggeringEventEvaluator evaluator = appender.getEvaluator();
    assertTrue(evaluator instanceof MockTriggeringEventEvaluator);
}
 
Example #25
Source File: Log4JLogger.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new logger with given configuration {@code cfgFile}.
 * <p>
 * If {@code watchDelay} is not zero, created logger will check the configuration file for changes once every
 * {@code watchDelay} milliseconds, and update its configuration if the file was changed.
 * See {@link DOMConfigurator#configureAndWatch(String, long)} for details.
 *
 * @param cfgFile Log4j configuration XML file.
 * @param watchDelay delay in milliseconds used to check configuration file for changes.
 * @throws IgniteCheckedException Thrown in case logger can't be created.
 */
public Log4JLogger(final File cfgFile, final long watchDelay) throws IgniteCheckedException {
    if (cfgFile == null)
        throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");

    if (!cfgFile.exists() || cfgFile.isDirectory())
        throw new IgniteCheckedException("Log4j configuration path was not found or is a directory: " + cfgFile);

    if (watchDelay < 0)
        throw new IgniteCheckedException("watchDelay can't be negative: " + watchDelay);

    cfg = cfgFile.getAbsolutePath();

    addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
        @Override public Logger apply(Boolean init) {
            if (init) {
                if (watchDelay > 0)
                    DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay);
                else
                    DOMConfigurator.configure(cfgFile.getPath());
            }

            return Logger.getRootLogger();
        }
    });

    quiet = quiet0;
}
 
Example #26
Source File: ConsoleProxy.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private static void configLog4j() {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL configUrl = loader.getResource("/conf/log4j-cloud.xml");
    if (configUrl == null)
        configUrl = ClassLoader.getSystemResource("log4j-cloud.xml");

    if (configUrl == null)
        configUrl = ClassLoader.getSystemResource("conf/log4j-cloud.xml");

    if (configUrl != null) {
        try {
            System.out.println("Configure log4j using " + configUrl.toURI().toString());
        } catch (URISyntaxException e1) {
            e1.printStackTrace();
        }

        try {
            File file = new File(configUrl.toURI());

            System.out.println("Log4j configuration from : " + file.getAbsolutePath());
            DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000);
        } catch (URISyntaxException e) {
            System.out.println("Unable to convert log4j configuration Url to URI");
        }
        // DOMConfigurator.configure(configUrl);
    } else {
        System.out.println("Configure log4j with default properties");
    }
}
 
Example #27
Source File: TestPubSub.java    From springJredisCache with Apache License 2.0 5 votes vote down vote up
@Before
public void IntiRes() {
    DOMConfigurator.configure("res/appConfig/log4j.xml");
    System.setProperty("java.net.preferIPv4Stack", "true"); //Disable IPv6 in JVM
    springContext = new FileSystemXmlApplicationContext("res/springConfig/spring-context.xml");
    /**初始化spring容器*/
    testPubSub = (TestPubSub) springContext.getBean("testPubSub");

}
 
Example #28
Source File: LittleProxyMitmProxy.java    From LittleProxy-mitm with Apache License 2.0 5 votes vote down vote up
public static void main(final String... args) throws Exception {
    File log4jConfigurationFile = new File("src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    new LittleProxyMitmProxy(9090).start();
    Server.waitUntilInterupted();
}
 
Example #29
Source File: Proxy.java    From LittleProxy-mitm with Apache License 2.0 5 votes vote down vote up
public static void main(final String... args) throws Exception{
    File log4jConfigurationFile = new File("src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    new Proxy(9090).start();
    Server.waitUntilInterupted();
}
 
Example #30
Source File: DefaultAgent.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private void initLogger(ProfilerConfig config) {
    final String location = config.readString(Profiles.LOG_CONFIG_LOCATION_KEY, null);
    if (location == null) {
        throw new IllegalStateException("$PINPOINT_DIR/profiles/${profile}/log4j.xml not found");
    }
    // log4j init
    DOMConfigurator.configure(location);
}