@Override public Logger apply(Boolean init) { if (init) { if (watchDelay > 0) DOMConfigurator.configureAndWatch(cfg, watchDelay); else DOMConfigurator.configure(cfg); } return Logger.getRootLogger(); } });
static void init(String portStr, String configFile) { try { port = Integer.parseInt(portStr); } catch(java.lang.NumberFormatException e) { e.printStackTrace(); usage("Could not interpret port number ["+ portStr +"]."); } if(configFile.endsWith(".xml")) { DOMConfigurator.configure(configFile); } else { PropertyConfigurator.configure(configFile); } } }
DOMConfigurator.configure(configFile); } else { PropertyConfigurator.configure(configFile);
@Override public Logger apply(Boolean init) { if (init) { if (watchDelay > 0) DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay); else DOMConfigurator.configure(cfgFile.getPath()); } return Logger.getRootLogger(); } });
@Override public Logger apply(Boolean init) { if (init) DOMConfigurator.configure(cfgUrl); return Logger.getRootLogger(); } });
@Override public Logger apply(Boolean init) { if (init) { if (watchDelay > 0) DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay); else DOMConfigurator.configure(cfgFile.getPath()); } return Logger.getRootLogger(); } });
@Override public Logger apply(Boolean init) { if (init) DOMConfigurator.configure(cfgUrl); return Logger.getRootLogger(); } });
@Override public Logger apply(Boolean init) { if (init) { if (watchDelay > 0) DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay); else DOMConfigurator.configure(cfgFile.getPath()); } return Logger.getRootLogger(); } });
@Override public Logger apply(Boolean init) { if (init) DOMConfigurator.configure(cfg); return Logger.getRootLogger(); } });
@Override public Logger apply(Boolean init) { if (init) { if (watchDelay > 0) DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay); else DOMConfigurator.configure(cfgFile.getPath()); } return Logger.getRootLogger(); } });
/** * @param user User name. */ private static void configureLog4j(String user) { String cfgFile = System.getProperty("IGNITE_TEST_PROP_LOG4J_FILE"); if (cfgFile == null) cfgFile = "log4j-test.xml"; File log4jFile = getTestConfigurationFile(user, cfgFile); if (log4jFile == null) log4jFile = getTestConfigurationFile(null, cfgFile); DOMConfigurator.configure(log4jFile.getAbsolutePath()); System.out.println("Configured log4j from: " + log4jFile); }
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 ); }
public static void main(String[] args) throws Exception { System.setProperty(DEFAULT_CONFIGURATION_KEY, "log4j-conf.xml"); Logger logger = Logger.getLogger(Log4jTest.class.getName()); logger.setLevel(Level.INFO); logger.info("Hello,World"); // 重新加载 log4j的配置 URL url = Thread.currentThread().getContextClassLoader().getResource("log4j-api.xml"); DOMConfigurator.configure(url); MDC.put("requestURI","https://segmemtfault.com"); logger = Logger.getLogger(Log4jTest.class.getName()); // 调整级别后输出 logger.info("Hello,World"); logger.error("大家好"); } }
static void init(String portStr, String configFile) { try { port = Integer.parseInt(portStr); } catch(java.lang.NumberFormatException e) { e.printStackTrace(); usage("Could not interpret port number ["+ portStr +"]."); } if(configFile.endsWith(".xml")) { DOMConfigurator.configure(configFile); } else { PropertyConfigurator.configure(configFile); } } }
private void configureLog4JInTest(String log4jConfSuffix) { DOMConfigurator.configure("src/test/resources/log4j-in-test-" + log4jConfSuffix + ".xml"); }
private void configureLog4J() { DOMConfigurator.configure("src/test/resources/log4j.xml"); }
static void init(String portStr, String configFile) { try { port = Integer.parseInt(portStr); } catch(java.lang.NumberFormatException e) { e.printStackTrace(); usage("Could not interpret port number ["+ portStr +"]."); } if(configFile.endsWith(".xml")) { new DOMConfigurator().configure(configFile); } else { new PropertyConfigurator().configure(configFile); } } }
/** * Initialize log4j from the given file location, with no config file refreshing. * Assumes an XML file in case of a ".xml" file extension, and a properties file * otherwise. * @param location the location of the config file: either a "classpath:" location * (e.g. "classpath:myLog4j.properties"), an absolute file URL * (e.g. "file:C:/log4j.properties), or a plain absolute path in the file system * (e.g. "C:/log4j.properties") * @throws FileNotFoundException if the location specifies an invalid file path */ public static void initLogging(String location) throws FileNotFoundException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); URL url = ResourceUtils.getURL(resolvedLocation); if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) { DOMConfigurator.configure(url); } else { PropertyConfigurator.configure(url); } }
DOMConfigurator.configure(configFile); } else { PropertyConfigurator.configure(configFile);
DOMConfigurator.configure("log4j.xml");