/** 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); }
/** * This method configures the <code>LF5Appender</code> using a * default configuration file. The default configuration file is * <bold>defaultconfig.properties</bold>. * @throws java.io.IOException */ public static void configure() throws IOException { String resource = "/org/apache/log4j/lf5/config/defaultconfig.properties"; URL configFileResource = DefaultLF5Configurator.class.getResource(resource); if (configFileResource != null) { PropertyConfigurator.configure(configFileResource); } else { throw new IOException("Error: Unable to open the resource" + resource); } }
private static void configLog(String configFile) { if(new File(configFile).exists()) { PropertyConfigurator.configure(configFile); return; } Properties properties = new Properties(); properties.setProperty("log4j.rootLogger", "DEBUG, CA"); properties.setProperty("log4j.appender.CA", "org.apache.log4j.ConsoleAppender"); properties.setProperty("log4j.appender.CA.layout", "org.apache.log4j.PatternLayout"); properties.setProperty("log4j.appender.CA.layout.ConversionPattern", "%d{yyyy-MM-dd HH:mm:ss.SSS} %-4r [%t] %-5p %c %x - %m%n"); PropertyConfigurator.configure(properties); } }
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); } } }
static void init(String portStr, String configFile, String dirStr) { try { port = Integer.parseInt(portStr); } catch(java.lang.NumberFormatException e) { e.printStackTrace(); usage("Could not interpret port number ["+ portStr +"]."); } PropertyConfigurator.configure(configFile); File dir = new File(dirStr); if(!dir.isDirectory()) { usage("["+dirStr+"] is not a directory."); } server = new SocketServer(dir); }
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); } } }
DOMConfigurator.configure(configFile); } else { PropertyConfigurator.configure(configFile);
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); } }
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);
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);
/** * 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(); } } }
PropertyConfigurator.configure(originalProperties); } catch (Throwable t) { throw closer.rethrow(t);
logprops.setProperty(loggerMaryttsKey, loggerMaryttsValue); PropertyConfigurator.configure(logprops);
logprops.setProperty(loggerMaryttsKey, loggerMaryttsValue); PropertyConfigurator.configure(logprops);
PropertyConfigurator.configure(log4jPath);
PropertyConfigurator.configure(log4jPath);
PropertyConfigurator.configure(log4jPath);
PropertyConfigurator.configure(log4jPath);