public static void updateLog4jConfiguration(Class<?> targetClass, String log4jPath) throws Exception { Properties customProperties = new Properties(); FileInputStream fs = null; InputStream is = null; try { fs = new FileInputStream(log4jPath); is = targetClass.getResourceAsStream("/log4j.properties"); customProperties.load(fs); Properties originalProperties = new Properties(); originalProperties.load(is); for (Entry<Object, Object> entry : customProperties.entrySet()) { originalProperties.setProperty(entry.getKey().toString(), entry .getValue().toString()); } LogManager.resetConfiguration(); PropertyConfigurator.configure(originalProperties); }finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fs); } } }
/** Like {@link #configureAndWatch(String, long)} except that the default delay as defined by {@link FileWatchdog#DEFAULT_DELAY} is used. @param configFilename A file in key=value format. */ static public void configureAndWatch(String configFilename) { configureAndWatch(configFilename, FileWatchdog.DEFAULT_DELAY); }
throws IOException { String inetAddressStr = mSocket.getInetAddress().getHostAddress(); Properties properties = new Properties(); File configFile; try { try (FileInputStream inputStream = new FileInputStream(configFile)) { properties.load(inputStream); properties.setProperty(ROOT_LOGGER_PROPERTY_KEY, level.toString() + "," + AlluxioLogServerProcess.LOGSERVER_CLIENT_LOGGER_APPENDER_NAME); properties.setProperty(ROOT_LOGGER_APPENDER_FILE_PROPERTY_KEY, logFilePath); new PropertyConfigurator().doConfigure(properties, clientHierarchy); return clientHierarchy;
/** Read configuration options from <code>properties</code>. See {@link #doConfigure(String, LoggerRepository)} for the expected format. */ static public void configure(Properties properties) { new PropertyConfigurator().doConfigure(properties, LogManager.getLoggerRepository()); }
LoggerRepository genericHierarchy() { if(genericHierarchy == null) { File f = new File(dir, GENERIC+CONFIG_FILE_EXT); if(f.exists()) { genericHierarchy = new Hierarchy(new RootLogger(Level.DEBUG)); new PropertyConfigurator().doConfigure(f.getAbsolutePath(), genericHierarchy); } else { cat.warn("Could not find config file ["+f+ "]. Will use the default hierarchy."); genericHierarchy = LogManager.getLoggerRepository(); } } return genericHierarchy; } }
LoggerRepository configureHierarchy(InetAddress inetAddress) { cat.info("Locating configuration file for "+inetAddress); // We assume that the toSting method of InetAddress returns is in // the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1 String s = inetAddress.toString(); int i = s.indexOf("/"); if(i == -1) { cat.warn("Could not parse the inetAddress ["+inetAddress+ "]. Using default hierarchy."); return genericHierarchy(); } else { String key = s.substring(0, i); File configFile = new File(dir, key+CONFIG_FILE_EXT); if(configFile.exists()) { Hierarchy h = new Hierarchy(new RootLogger(Level.DEBUG)); hierarchyMap.put(inetAddress, h); new PropertyConfigurator().doConfigure(configFile.getAbsolutePath(), h); return h; } else { cat.warn("Could not find config file ["+configFile+"]."); return genericHierarchy(); } } }
String log4jPath = confPath + "/log4j.properties"; Properties conf = new Properties(); File file = new File(cfgPath); InputStream is = null; try { is = new FileInputStream(file); } catch (FileNotFoundException e) { throw new CfgException("can not find " + cfgPath); conf.load(is); } catch (IOException e) { throw new CfgException("Read " + cfgPath + " error.", e); String registryAddress = conf.getProperty("registryAddress"); Assert.hasText(registryAddress, "registryAddress can not be null."); cfg.setRegistryAddress(registryAddress); PropertyConfigurator.configure(log4jPath);
private void setupLog4j(String log4jPath, String datasourceName) throws IOException { Properties p = new Properties(); InputStream is = null; try { is = new FileInputStream(log4jPath); p.load(is); p.put("log.datasource", datasourceName); // overwrite "log.dir" PropertyConfigurator.configure(p); } finally { IOUtils.closeQuietly(is); } }
/** * Read configuration options from url <code>configURL</code>. * * @since 1.2.17 */ public void doConfigure(InputStream inputStream, LoggerRepository hierarchy) { Properties props = new Properties(); try { props.load(inputStream); } catch (IOException e) { if (e instanceof InterruptedIOException) { Thread.currentThread().interrupt(); } LogLog.error("Could not read configuration file from InputStream [" + inputStream + "].", e); LogLog.error("Ignoring configuration InputStream [" + inputStream +"]."); return; } this.doConfigure(props, hierarchy); }
Properties props = new Properties(); FileInputStream istream = null; try { istream = new FileInputStream(configFileName); props.load(istream); istream.close(); Thread.currentThread().interrupt(); LogLog.error("Could not read configuration file ["+configFileName+"].", e); LogLog.error("Ignoring configuration file [" + configFileName+"]."); return; } finally { if(istream != null) { try { istream.close(); } catch(InterruptedIOException ignore) { Thread.currentThread().interrupt(); doConfigure(props, hierarchy);
Properties logprops = new Properties(); InputStream propIS = new BufferedInputStream(MaryProperties.needStream("log.config")); logprops.load(propIS); propIS.close(); for (Object key : logprops.keySet()) { String val = (String) logprops.get(key); if (val.contains("MARY_BASE")) { logprops.setProperty(loggerMaryttsKey, loggerMaryttsValue); PropertyConfigurator.configure(logprops);
public static void main(String[] args) throws Exception { Properties p = new Properties(); File in = new File(args[0]); FileInputStream fis = null; try { fis = new FileInputStream(in); p.load(fis); } finally { fis.close(); } BasicConfigurator.configure(); PropertyConfigurator.configure(args[0]); Logger.getLogger(MultiRunner.class).info("MultiRunner.class"); MultiRunner m = new MultiRunner(p); m.runThreads(); } }
Enumeration a = LogManager.getRootLogger().getAllAppenders(); while (a.hasMoreElements()) { Appender appender = (Appender) a.nextElement(); Properties lprops = new Properties(); lprops.load(loggingConfigStream); LogManager.resetConfiguration(); PropertyConfigurator.configure(lprops); Appender gslf = org.apache.log4j.Logger.getRootLogger().getAppender("geoserverlogfile"); if (gslf instanceof org.apache.log4j.FileAppender) { if (logFileName == null) { lprops.setProperty("log4j.appender.geoserverlogfile.File", logFileName); PropertyConfigurator.configure(lprops); LoggingInitializer.LOGGER.fine("Logging output to file '" + logFileName + "'"); } else if (gslf != null) { LogManager.getRootLogger().addAppender(appender);
/** * Update the log4j configuration. * * @param targetClass the target class used to get the original log4j configuration file as a resource * @param log4jFileName the custom log4j configuration properties file name * @throws IOException if there's something wrong with updating the log4j configuration */ public static void updateLog4jConfiguration(Class<?> targetClass, String log4jFileName) throws IOException { final Closer closer = Closer.create(); try { final InputStream inputStream = closer.register(targetClass.getResourceAsStream("/" + log4jFileName)); final Properties originalProperties = new Properties(); originalProperties.load(inputStream); LogManager.resetConfiguration(); PropertyConfigurator.configure(originalProperties); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } } }
level = DEFAULT_LOG4J_LEVEL; Properties properties = new Properties(); properties.setProperty("log4j.rootLogger", level + ",application"); properties.setProperty("log4j.appender.application", "org.apache.log4j.DailyRollingFileAppender"); properties.setProperty("log4j.appender.application.File", file); properties.setProperty("log4j.appender.application.Append", "true"); properties.setProperty("log4j.appender.application.layout", "org.apache.log4j.PatternLayout"); properties.setProperty("log4j.appender.application.layout.ConversionPattern", "%d [%t] %-5p %C{6} (%F:%L) - %m%n"); PropertyConfigurator.configure(properties); Enumeration<org.apache.log4j.Logger> ls = LogManager.getCurrentLoggers(); while (ls.hasMoreElements()) { org.apache.log4j.Logger l = ls.nextElement(); if (l != null) { Enumeration<Appender> as = l.getAllAppenders(); while (as.hasMoreElements()) { Appender a = as.nextElement();
/** initialise log4j **/ private static void initLog4J() { final Properties props = new Properties(); props.setProperty("log4j.rootLogger", "DEBUG, A1"); props.setProperty("log4j.appender.A1", "org.apache.log4j.ConsoleAppender"); props.setProperty("log4j.appender.A1.layout", "org.apache.log4j.TTCCLayout"); PropertyConfigurator.configure(props); }
private static void initialiseLogger() { final Properties logProperties = new Properties(); try (InputStream in = Main.class.getResourceAsStream("/log4j-standalone.properties")) { logProperties.load(in); PropertyConfigurator.configure(logProperties); Logger.getLogger(Main.class).info("Logging initialized."); } catch (final IOException e) { throw new RuntimeException("Unable to load logging"); } } }
private static org.apache.log4j.Logger createLog4jLogger(String logDirParent) { synchronized (water.util.Log.class) { if (_logger != null) { return _logger; } // If a log4j properties file was specified on the command-line, use it. // Otherwise, create some default properties on the fly. String log4jProperties = System.getProperty ("log4j.properties"); if (log4jProperties != null) { PropertyConfigurator.configure(log4jProperties); // TODO: Need some way to set LOG_DIR here for LogCollectorTask to work. } else { java.util.Properties p = new java.util.Properties(); setLog4jProperties(logDirParent, p); PropertyConfigurator.configure(p); } _logger = LogManager.getLogger(Log.class.getName()); } return _logger; }
/** * Configures root logger, either for FILE output or just console. */ public static void configureLogger() { LogManager.shutdown(); String logFile = getConfigBoolean("log.save", false) ? "log4j.file.properties" : "log4j.properties"; try (InputStream stream = Utils.class.getClassLoader().getResourceAsStream(logFile)) { if (stream == null) { PropertyConfigurator.configure("src/main/resources/" + logFile); } else { PropertyConfigurator.configure(stream); } LOGGER.info("Loaded " + logFile); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } }
public static EmbeddedIndexEngine instantiate(String[] args) throws IOException{ String log4jConfigPath = com.flaptor.util.FileUtil.getFilePathFromClasspath("log4j.properties"); if (null != log4jConfigPath) { org.apache.log4j.PropertyConfigurator.configureAndWatch(log4jConfigPath); } else { logger.warn("log4j.properties not found on classpath!"); environment = ""; logger.info("Command line option 'environment-prefix' set to " + environment); logger.info("Command line option 'facets' set to " + facets); String indexCode = line.getOptionValue("index-code"); logger.info("Command line option 'index-code' set to " + indexCode);