/** Initialize log4j using the file specified in the 'framework.Log4JConfig' property in the config.properties file. * This will be set to either 'none', 'default' or a classpath-relative file name. If there is no configuration setting * 'default' wil be assumed. * * For more information look at the documentation in 'config.properties' */ private void initLog4j() { //Read setting from configuration file String fileName = (String) Config.getProperty(Config.PROP_LOG4J_CONFIG, "default"); if ( fileName.equalsIgnoreCase("none") ) { // do nothing.. Assume that log4j would have been initialized by some other container initializeLogField(); log.info("Skipped log4j configuration. Should be done by Web/J2EE Server first!"); } else if ( fileName.equalsIgnoreCase("default") ) { defaultLog4j(); } else { try { URL u = URLHelper.newExtendedURL(fileName); DOMConfigurator.configureAndWatch(u.getPath()); initializeLogField(); if ( log.isInfoEnabled() ) log.info("Configured log4j using the configuration file (relative to classpath): " + fileName ); } catch (Exception e) { System.err.println( "Error in initializing Log4j using the configFile (relative to classpath): " + fileName ); e.printStackTrace(); defaultLog4j(); } } }
public synchronized static void initializeLogger() { if(isInitialized) return; InputStream configStream = null; try { configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("log4j.xml"); if(configStream != null){ new DOMConfigurator().doConfigure(configStream, LogManager.getLoggerRepository()); } else { System.out.println("Error reading log configurstion file. Could not initialize logger."); } } finally{ if(configStream != null){ try { configStream.close(); } catch (IOException e) { e.printStackTrace(); } } } isInitialized = true; }
private void init() { try { final VirtualFile logXml = LuaFileUtil.getPluginVirtualDirectoryChild("log.xml"); File logXmlFile = new File(logXml.getPath()); 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, LOG_DIR_MACRO, StringUtil.replace(PathManager.getLogPath(), "\\", "\\\\")); new DOMConfigurator().doConfigure(new StringReader(text), LogManager.getLoggerRepository()); } catch (Exception e) { e.printStackTrace(); } }
/** * This method should only really be called once per context in the context startup listener. * * The purpose of this is to allow customisations to the logging on a per-deployment basis with out * needing to commit the configuration to cvs while at the same time allowing you to keep your * configuration through multiple deployments. As an example, if you modified the WEB-INF/classes/log4j.xml * either you have to commit that and everyone gets your configuration, or you don't commit it, * every new deploy will over write changes you made locally to your log4j.xml. This helper method alleviates this problem. * * The functionality of this is as follows : * * The system configuration parameter "log4j.override.configuration" specifies the file to use * to override overlay on top of the default log4j.xml file. This can be a relative or absolute path. * An example maybe "/home/foo/my_override_log4j.xml" * * The filename specified is allowed to have a special placeholder ${contextName}, this allows the * system variable to be used when multiple oscar contexts exist. As an example it maybe * "/home/foo/${contextName}_log4.xml". During runtime, when each context startup calls this method * the ${contextName} is replaced with the contextPath. So as an example of you had 2 contexts called * "asdf" and "zxcv" respectively, it will look for /home/foo/asdf_log4j.xml and /home/foo/zxcv_log4j.xml. */ protected static void addLoggingOverrideConfiguration(String contextPath) { String configLocation = System.getProperty("log4j.override.configuration"); if (configLocation != null) { if (configLocation.contains("${contextName}")) { if (contextPath != null) { if (contextPath.length() > 0 && contextPath.charAt(0) == '/') contextPath = contextPath.substring(1); if (contextPath.length() > 0 && contextPath.charAt(contextPath.length() - 1) == '/') contextPath = contextPath.substring(0, contextPath.length() - 2); } configLocation=configLocation.replace("${contextName}", contextPath); } getLogger().info("loading additional override logging configuration from : "+configLocation); DOMConfigurator.configureAndWatch(configLocation); } }
@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>(); // logger = LoggerFactory.getLogger(ALBIAN_LOGGER); } catch (Exception exc) { throw new AlbianServiceException(exc.getMessage(), exc.getCause()); } }
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); } }
public static void main(String argv[]) { DOMConfigurator.configureAndWatch("log4j.xml", 60 * 1000); TestDriver testDriver = new TestDriver(argv); testDriver.init(); System.out.println("\nStarting test...\n"); if (testDriver.multithreading) { testDriver.runMT(); System.out.println("\n" + testDriver.printResults(true)); } else if (testDriver.qualification) testDriver.runQualification(); else if (testDriver.rampup) testDriver.runRampup(); else { testDriver.run(); System.out.println("\n" + testDriver.printResults(true)); } }
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); }
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); }
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)); }
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")); }
public void loadLog4jConfig(String log4jConfigPath) throws FileNotFoundException{ File file = null; if(log4jConfigPath!=null){ file = new File(log4jConfigPath); }else { file = new File(CONFIG_PATH + LOG4J_XML); if (!file.exists()) { file = new File(CONFIG_PATH + LOG4J_PROPERTIES); } if(!file.exists()) { URL url = this.getClass().getResource("/" + LOG4J_XML); file = new File(url.getFile()); } } if(file.exists()){ log.info("loading log4j conf " + file.getAbsolutePath()); String log4jConf = file.getName(); if(log4jConf.endsWith(".xml")){ DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 60); }else if(log4jConf.endsWith(".properties")){ PropertyConfigurator.configureAndWatch(file.getAbsolutePath(), 60); } }else{ throw new FileNotFoundException(file.getAbsolutePath()); } }
public static boolean loadLog4JConfigXml(File directory) { File f = new File(directory, CONFIG_FILENAME); if (!f.isFile()) return false; try { DOMConfigurator.configure(f.getAbsolutePath()); } catch (Exception e) { System.err.println("Error loading log4j config file \"" + f.getAbsolutePath() + "\""); return false; } Logger logger = Logger.getLogger("LogSystem"); logger.setLevel(Level.INFO); logger.info("Logging configured by \"" + f.getAbsolutePath() + "\""); CONFIGURED = true; return true; }
/** * 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 Log4JLogger(final 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; }
/** * 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 Log4JLogger(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; }
/** * 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 Log4JLogger(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; }
/** * 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; }
/** * 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; }
/** * 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; }
public void resetConfiguration(String location, long refreshInterval) { URL url = this.getClass().getResource(location); if (url != null) { LogManager.getRootLogger().removeAllAppenders(); LogManager.resetConfiguration(); if (location.toLowerCase().endsWith(".xml")) if (refreshInterval == 0) DOMConfigurator.configure(url); else DOMConfigurator.configureAndWatch(location,refreshInterval); else if (refreshInterval == 0) PropertyConfigurator.configure(url); else PropertyConfigurator.configureAndWatch(location,refreshInterval); } else { logger.error("Could not find the following file: " + location); } }
/** * <p> * main. * </p> * * @param args a {@link java.lang.String} object. * @throws java.lang.Throwable if any. */ public static void main(final String... args) throws Throwable { final AppContext cfg = new AppContext(workDir()); LogManager.resetConfiguration(); DOMConfigurator.configure(cfg.log4jConfigFileName); try { Funnel.sort(cfg, args); } catch (final ParseException e) { System.out.println(e.getMessage()); } System.exit(0); }
/** * @param configLocation location. */ protected void initLogging(final String configLocation) { log("initLogging [" + configLocation + "]."); URL url = null; try { url = new URL(configLocation); log("found url: " + url); } catch (@SuppressWarnings("unused") final MalformedURLException ex) { // so, resource is not a URL: // attempt to get the resource from the class path log("attempt to get the resource from the class path."); url = Loader.getResource(configLocation); } if (url != null) { log("Using URL [" + url + "] for automatic log4j configuration."); if (configLocation.toLowerCase(Locale.ENGLISH).endsWith(".xml")) { DOMConfigurator.configure(url); } else { PropertyConfigurator.configure(url); } } else { log("Could not find resource: [" + configLocation + "]."); } }
/** * @param args * @throws Exception */ public static void main(String[] args) { try { DOMConfigurator.configure("log4j.xml"); boolean test_single = false; if (test_single) testSingle(new TraditionalWChainPGP()); else testAll(); } catch (Exception e) { logger.error("Exceptions occured in main program: "); logger.error(e.getMessage()); } }
Logger initLog4j(File webappRoot) { // all occurrences of ${com.imcode.imcms.path} must be replaced with real WEB_APP root path. String WEBAPP_ROOT_RE = "(?i)\\$\\{\\s*com\\.imcode\\.imcms\\.path\\s*\\}"; File log4jConfFile = new File(webappRoot, "WEB-INF/conf/log4j.xml"); if (!log4jConfFile.exists()) { throw new RuntimeException(String.format("Log4j configuration file %s does not exists.", log4jConfFile)); } try { String webappRootPath = webappRoot.getCanonicalPath().replaceAll("\\\\", "/"); String log4jConf = FileUtils .readFileToString(log4jConfFile, "utf-8") .replaceAll(WEBAPP_ROOT_RE, Matcher.quoteReplacement(webappRootPath)); Reader log4jConfReader = new StringReader(log4jConf); new DOMConfigurator().doConfigure(log4jConfReader, LogManager.getLoggerRepository()); } catch (IOException e) { throw new RuntimeException("Error occurred while reading log4.xml file", e); } return Logger.getLogger(getClass()); }
private void setAppenderForLogger() { String cleanMac = settop.getLogDirectory(); if ( cleanMac == null ) { cleanMac = "UnknownMac"; } Map<String,String> mdcMap = new HashMap<String,String>(); mdcMap.put("SettopMac", cleanMac); mdcMap.put("LogFileName", "RebootDetection.log"); MDC.setContextMap(mdcMap); URL logFileUrl = getClass().getResource("/reboot-report-log4j.xml" ); DOMConfigurator.configure( logFileUrl ); rebootDetectionLogger = LoggerFactory.getLogger("RebootDetection"); }
public void report( RebootStatistics detail ) { if ( detail != null ) { this.lastReboot = detail; reboots.add( detail ); Map<String,String> mdcMap = new HashMap<String,String>(); mdcMap.put("SettopMac", settop.getLogDirectory()); mdcMap.put("LogFileName", "RebootDetection.log"); MDC.setContextMap(mdcMap); URL logFileUrl = getClass().getResource( "/reboot-report-log4j.xml" ); DOMConfigurator.configure( logFileUrl ); rebootDetectionLogger.info( "{}", detail ); if ( reportAggregator != null ) { reportAggregator.aggregateReport( detail ); } } }
@Override public void init(Map params, File configDir) throws MetadataProviderException { String logConfig = (String) params.get("log_config"); if (logConfig != null) { File logConfigFile = new File(configDir, logConfig); String logRefresh = (String) params.get("log_config_refresh_seconds"); if (logRefresh != null) { DOMConfigurator.configureAndWatch(logConfigFile.getAbsolutePath(), Integer.parseInt(logRefresh) * 1000); } else { DOMConfigurator.configure(logConfigFile.getAbsolutePath()); } } //else the bridge to logback is expected logger = Logger.getLogger(Constants.LOGGER_CAT); // Read the Adapter Set name, which is supplied by the Server as a parameter this.adapterSetId = (String) params.get("adapters_conf.id"); }
/** * @param args the command line arguments */ public static void main(String[] args) { // optionally we can start the gui under a different configuration folder String definitionsConfigFolder =""; if (args.length > 0 ) { definitionsConfigFolder = args[0]; if(definitionsConfigFolder.equals(".")){ definitionsConfigFolder = ""; }else if(!definitionsConfigFolder.endsWith("/")){ definitionsConfigFolder=definitionsConfigFolder+"/"; } } DOMConfigurator.configure(definitionsConfigFolder+"generator.xml"); ApplicationContext.setDefinitionsConfigurationFolder(definitionsConfigFolder); //Start the GUI MainForm frmMain = new MainForm(); frmMain.setVisible(true); }
/** * Main method for Ilves seed project. * * @param args the commandline arguments * @throws Exception if exception occurs in jetty startup. */ public static void main(final String[] args) throws Exception { // Configure logging. DOMConfigurator.configure("log4j.xml"); // Construct jetty server. final Server server = Ilves.configure(PROPERTIES_FILE_PREFIX, LOCALIZATION_BUNDLE_PREFIX, PERSISTENCE_UNIT); // Initialize modules Ilves.initializeModule(AuditModule.class); Ilves.initializeModule(CustomerModule.class); Ilves.initializeModule(ContentModule.class); Ilves.addRootPage(0, "custom", DefaultValoView.class); Ilves.setPageComponent("custom", Slot.CONTENT, WelcomeComponent.class); Ilves.setPageComponent("custom", Slot.FOOTER, CommentingComponent.class); Ilves.setDefaultPage("custom"); // Start server. server.start(); // Wait for exit of the Jetty server. server.join(); }
public Log(){ // imagine all dependencies would ship their own log4j property file // and would require different parameters for log directory... // however, we can do two small hacks to make it usable! // do not even try to output to "/debug.log" if ( null == System.getProperty("RP_LOG_DIR") ) { return; } // do not use log4j.xml which might get loaded by default!!! _log4jXmlPath= "b2safe-log4j.xml"; // DOMConfigurator.configure(Log.class.getResource(_log4jXmlPath)); DOMConfigurator.configure(this.getClass().getClassLoader().getResource(_log4jXmlPath)); }
/** * Main method for Ilves seed project. * * @param args the commandline arguments * @throws Exception if exception occurs in jetty startup. */ public static void main(final String[] args) throws Exception { // Configure logging. DOMConfigurator.configure("log4j.xml"); // Construct jetty server. final Server server = Ilves.configure(PROPERTIES_FILE_PREFIX, LOCALIZATION_BUNDLE_PREFIX, PERSISTENCE_UNIT); // Initialize modules Ilves.initializeModule(AuditModule.class); Ilves.initializeModule(CustomerModule.class); Ilves.initializeModule(ContentModule.class); Ilves.addNavigationCategoryPage(0, "custom"); Ilves.addChildPage("custom", "comments", DefaultValoView.class); Ilves.setPageComponent("comments", Slot.CONTENT, HelloComponent.class); Ilves.setPageComponent("comments", Slot.FOOTER, CommentingComponent.class); Ilves.setDefaultPage("comments"); // Start server. server.start(); // Wait for exit of the Jetty server. server.join(); }
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); } } }
@Override @SuppressWarnings("rawtypes") public void init(Map params, File configDir) throws MetadataProviderException { // Call super's init method to handle basic Metadata Adapter features super.init(params, configDir); String logConfig = (String) params.get("log_config"); if (logConfig != null) { File logConfigFile = new File(configDir, logConfig); String logRefresh = (String) params.get("log_config_refresh_seconds"); if (logRefresh != null) { DOMConfigurator.configureAndWatch(logConfigFile.getAbsolutePath(), Integer.parseInt(logRefresh) * 1000); } else { DOMConfigurator.configure(logConfigFile.getAbsolutePath()); } } logger = Logger.getLogger("LS_demos_Logger.StockQuotesMetadata"); logger.info("StockQuotesMetadataAdapter ready"); }
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."); }
/** * Constructs a new test with the given name. * * @param name the name of the test */ public SPGDayUnitTest(String name) { super(name); // Load the logging configuration BasicConfigurator.configure(); try { DOMConfigurator.configure(new URL(System.getProperty( "log4j.configuration"))); } catch (MalformedURLException mue) { log.error("Unable to configure logging service from XML configuration " + "file", mue); } }
/** * Loads the embedded logging configuration (from the JAR file). */ private void loadLoggingConfig() { // get a URL from the classloader for the logging configuration URL log4jConfigUrl = ClassLoader.getSystemResource(LOG4J_CONFIG_PATH); // if we didn't get a URL, tell the user that something went wrong if (log4jConfigUrl == null) { System.err.println("Unable to find logging configuration file in JAR " + "with " + LOG4J_CONFIG_PATH + ", reverting to default configuration."); BasicConfigurator.configure(); } else { try { // configure the logging service DOMConfigurator.configure(log4jConfigUrl); log.info("Using logging configuration from " + log4jConfigUrl); } catch (FactoryConfigurationError e) { System.err.println("Unable to configure logging service"); } } }
private static void configureLog4j(final String homeDir) { File etcDir = new File(homeDir, "etc"); File xmlFile = new File(etcDir, "log4j.xml"); if (xmlFile.exists()) { DOMConfigurator.configureAndWatch(xmlFile.getAbsolutePath()); } else { File propertiesFile = new File(etcDir, "log4j.properties"); if (propertiesFile.exists()) { PropertyConfigurator.configureAndWatch(propertiesFile.getAbsolutePath()); } else { System.err.println("Could not find a Log4j configuration file at " + xmlFile.getAbsolutePath() + " or " + propertiesFile.getAbsolutePath() + ". Exiting."); System.exit(1); } } }
private void configureLog4j() { File homeDir = new File(System.getProperty("opennms.home")); File etcDir = new File(homeDir, "etc"); File xmlFile = new File(etcDir, "log4j.xml"); if (xmlFile.exists()) { DOMConfigurator.configureAndWatch(xmlFile.getAbsolutePath()); } else { File propertiesFile = new File(etcDir, "log4j.properties"); if (propertiesFile.exists()) { PropertyConfigurator.configureAndWatch(propertiesFile.getAbsolutePath()); } else { die("Could not find a Log4j configuration file at " + xmlFile.getAbsolutePath() + " or " + propertiesFile.getAbsolutePath() + ". Exiting."); } } /* * This is causing infinite recursion on exit * CaptchaStds.captchaStdOut(); */ }
/** * Fires up log4j logging services within the application. This method * <b>MUST</b> be called before the config file will be used. Before this * method is called, any log messages will be handled by whatever default * logging configuration (if any) log4j uses. */ public static void startLogger() { if (LogUtils.isStarted) { return; } DOMConfigurator.configureAndWatch(LogUtils.CONFG_FILE, LogUtils.RELOAD_INTERVAL); Logger logger = Logger.getLogger(LogUtils.class); logger.info("Log4J started up and ready to go. My configuration file is '" + LogUtils.CONFG_FILE + "'. My configuration is reloaded every " + (LogUtils.RELOAD_INTERVAL / 1000) + " seconds."); LogUtils.isStarted = true; return; }