本文整理汇总了Java中org.apache.log4j.PropertyConfigurator.configureAndWatch方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyConfigurator.configureAndWatch方法的具体用法?Java PropertyConfigurator.configureAndWatch怎么用?Java PropertyConfigurator.configureAndWatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.PropertyConfigurator
的用法示例。
在下文中一共展示了PropertyConfigurator.configureAndWatch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLog
import org.apache.log4j.PropertyConfigurator; //导入方法依赖的package包/类
/**
* Initializes Log4j logging.
*
* @throws ServerException thrown if Log4j could not be initialized.
*/
protected void initLog() throws ServerException {
verifyDir(logDir);
LogManager.resetConfiguration();
File log4jFile = new File(configDir, name + "-log4j.properties");
if (log4jFile.exists()) {
PropertyConfigurator.configureAndWatch(log4jFile.toString(), 10 * 1000); //every 10 secs
log = LoggerFactory.getLogger(Server.class);
} else {
Properties props = new Properties();
try {
InputStream is = getResource(DEFAULT_LOG4J_PROPERTIES);
try {
props.load(is);
} finally {
is.close();
}
} catch (IOException ex) {
throw new ServerException(ServerException.ERROR.S03, DEFAULT_LOG4J_PROPERTIES, ex.getMessage(), ex);
}
PropertyConfigurator.configure(props);
log = LoggerFactory.getLogger(Server.class);
log.warn("Log4j [{}] configuration file not found, using default configuration from classpath", log4jFile);
}
}
示例2: initLogging
import org.apache.log4j.PropertyConfigurator; //导入方法依赖的package包/类
private void initLogging(String confDir) {
if (System.getProperty("log4j.configuration") == null) {
System.setProperty("log4j.defaultInitOverride", "true");
boolean fromClasspath = true;
File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile();
if (log4jConf.exists()) {
PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000);
fromClasspath = false;
} else {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL log4jUrl = cl.getResource(LOG4J_PROPERTIES);
if (log4jUrl != null) {
PropertyConfigurator.configure(log4jUrl);
}
}
LOG = LoggerFactory.getLogger(KMSWebApp.class);
LOG.debug("KMS log starting");
if (fromClasspath) {
LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES);
LOG.warn("Logging with INFO level to standard output");
}
} else {
LOG = LoggerFactory.getLogger(KMSWebApp.class);
}
}
示例3: initializeLogging
import org.apache.log4j.PropertyConfigurator; //导入方法依赖的package包/类
public static void initializeLogging()
{
if (StringUtils.isBlank(System.getProperty("log.file.path")))
{
// get the jar file directory, go one step above, and then set to log directory
String logfilePath = null;
try
{
logfilePath = AbstractJMSClient.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
logfilePath += File.separator + ".." + File.separator + ".." + File.separator + "log";
logfilePath = new File(logfilePath).getCanonicalPath();
}
catch (Exception e)
{
logfilePath = ".";
}
System.setProperty("log.file.path", logfilePath);
}
if(StringUtils.isBlank(System.getProperty("log.file")))
{
System.setProperty("log.file", "jmsclient.log");
}
PropertyConfigurator.configure(System.getProperties());
PropertyConfigurator.configureAndWatch(
AbstractJMSClient.class.getResource(File.separator + "log4j.properties").getPath(), PROPERTIES_REFRESH);
}
示例4: setLogLevel
import org.apache.log4j.PropertyConfigurator; //导入方法依赖的package包/类
/**
* Sets the log level for the given logger. If there is no property file to
* be used, the log level will be set to the value as given in the level
* parameter.
*
* @param logger
* The logger to be modified.
* @param level
* The log level to be set if no property file can be found.
*/
private static void setLogLevel(Log4jLogger logger, Level level) {
if (logConfigPath != null && new File(logConfigPath).exists()) {
PropertyConfigurator.configureAndWatch(logConfigPath, 60000);
} else {
logger.systemLogger.setLevel(level);
logger.auditLogger.setLevel(level);
// used INFO log level as default for the reverse proxy logger
logger.proxyLogger.setLevel(Level.INFO);
// all access operations will be logged with info level
logger.accessLogger.setLevel(Level.INFO);
}
}
示例5: init
import org.apache.log4j.PropertyConfigurator; //导入方法依赖的package包/类
/**
* 可以动态修改log级别 载入log4j配置文件
*/
public static void init() {
PropertyConfigurator.configureAndWatch(System.getProperty("user.dir") + "/conf/log4j.properties", 5000L);
}