congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
PropertyConfigurator
Code IndexAdd Tabnine to your IDE (free)

How to use
PropertyConfigurator
in
org.apache.log4j

Best Java code snippets using org.apache.log4j.PropertyConfigurator (Showing top 20 results out of 2,286)

Refine searchRefine arrow

  • Properties
  • LogManager
  • OptionConverter
  • LogLog
  • Logger
  • LoggerRepository
  • FileInputStream
origin: alibaba/jstorm

  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);
    }
  }
}
origin: log4j/log4j

/**
  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);
}
origin: Alluxio/alluxio

 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;
origin: log4j/log4j

/**
  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());
}
origin: log4j/log4j

 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;
 }
}
origin: log4j/log4j

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();
  }
 }
}
origin: ltsopensource/light-task-scheduler

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);
origin: alexholmes/hdfs-file-slurper

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);
 }
}
origin: log4j/log4j

/**
 * 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);
}
origin: log4j/log4j

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);
origin: marytts/marytts

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);
origin: hyperic/hq

  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();
  }
}
origin: geoserver/geoserver

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);
origin: apache/incubator-gobblin

 /**
  * 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();
  }
 }
}
origin: apache/incubator-dubbo

  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();
origin: log4j/log4j

/** 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);
}
origin: com.atlassian.plugins/atlassian-plugins-main

  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");
    }
  }
}
origin: h2oai/h2o-2

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;
}
origin: RipMeApp/ripme

/**
 * 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);
  }
}
origin: linkedin/indextank-engine

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);
org.apache.log4jPropertyConfigurator

Javadoc

Allows the configuration of log4j from an external file. See #doConfigure(String,LoggerRepository) for the expected format.

It is sometimes useful to see how log4j is reading configuration files. You can enable log4j internal logging by defining the log4j.debug variable.

As of log4j version 0.8.5, at class initialization time class, the file log4j.properties will be searched from the search path used to load classes. If the file can be found, then it will be fed to the PropertyConfigurator#configure(java.net.URL)method.

The PropertyConfigurator does not handle the advanced configuration features supported by the org.apache.log4j.xml.DOMConfigurator such as support for org.apache.log4j.spi.Filter, custom org.apache.log4j.spi.ErrorHandler, nested appenders such as the org.apache.log4j.AsyncAppender, etc.

All option values admit variable substitution. The syntax of variable substitution is similar to that of Unix shells. The string between an opening "${" and closing "}" is interpreted as a key. The value of the substituted variable can be defined as a system property or in the configuration file itself. The value of the key is first searched in the system properties, and if not found there, it is then searched in the configuration file being parsed. The corresponding value replaces the ${variableName} sequence. For example, if java.home system property is set to /home/xyz, then every occurrence of the sequence ${java.home} will be interpreted as /home/xyz.

Most used methods

  • configure
    Read configuration options from properties. See #doConfigure(String,LoggerRepository) for the expect
  • configureAndWatch
    Read the configuration file configFilename if it exists. Moreover, a thread will be created that wil
  • <init>
  • doConfigure
    Read configuration options from properties. See #doConfigure(String,LoggerRepository) for the expect
  • configureLoggerFactory
    Check the provided Properties object for a org.apache.log4j.spi.LoggerFactoryentry specified by #LOG
  • configureRootCategory
  • parseAdditivityForLogger
    Parse the additivity option for a non-root category.
  • parseAppender
  • parseCategory
    This method must work for the root category as well.
  • parseCatsAndRenderers
    Parse non-root elements, such non-root categories and renderers.
  • registryGet
  • registryPut
  • registryGet,
  • registryPut,
  • parseAppenderFilters,
  • parseErrorHandler

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSystemService (Context)
  • setContentView (Activity)
  • setScale (BigDecimal)
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JButton (javax.swing)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now