本文整理汇总了Java中org.apache.log4j.xml.DOMConfigurator.configureAndWatch方法的典型用法代码示例。如果您正苦于以下问题:Java DOMConfigurator.configureAndWatch方法的具体用法?Java DOMConfigurator.configureAndWatch怎么用?Java DOMConfigurator.configureAndWatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.xml.DOMConfigurator
的用法示例。
在下文中一共展示了DOMConfigurator.configureAndWatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLog4j
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
/** 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();
}
}
}
示例2: addLoggingOverrideConfiguration
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
/**
* 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);
}
}
示例3: main
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
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);
}
}
示例4: main
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
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));
}
}
示例5: loadLog4jConfig
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
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());
}
}
示例6: resetConfiguration
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
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);
}
}
示例7: init
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
@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");
}
示例8: init
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
@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");
}
开发者ID:Lightstreamer,项目名称:Lightstreamer-example-MPNStockListMetadata-adapter-java,代码行数:23,代码来源:StockQuotesMetadataAdapter.java
示例9: configureLog4j
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
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);
}
}
}
示例10: configureLog4j
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
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();
*/
}
示例11: startLogger
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
/**
* 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;
}
示例12: setUp
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
@Override
protected void setUp() {
URL configUrl = System.class.getResource("/conf/log4j-cloud.xml");
if (configUrl != null) {
System.out.println("Configure log4j using log4j-cloud.xml");
try {
File file = new File(configUrl.toURI());
System.out.println("Log4j configuration from : " + file.getAbsolutePath());
DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000);
} catch (URISyntaxException e) {
System.out.println("Unable to convert log4j configuration Url to URI");
}
} else {
System.out.println("Configure log4j with default properties");
}
}
示例13: setupLog4j
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
private static void setupLog4j() {
URL configUrl = System.class.getResource("/resources/log4j-cloud.xml");
if (configUrl != null) {
System.out.println("Configure log4j using log4j-cloud.xml");
try {
File file = new File(configUrl.toURI());
System.out.println("Log4j configuration from : " + file.getAbsolutePath());
DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000);
} catch (URISyntaxException e) {
System.out.println("Unable to convert log4j configuration Url to URI");
}
} else {
System.out.println("Configure log4j with default properties");
}
}
示例14: initPastryEnvironment
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
public void initPastryEnvironment(InetAddress inetAddress, int port) {
LOG.debug(String.format("initPastryEnvironment(%s, %d)", inetAddress.getHostAddress(), port));
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
TimeSource timeSource = Environment.generateDefaultTimeSource();
RandomSource randomSource = Environment.generateDefaultRandomSource(parameters, logManager);
Processor proc = Environment.generateDefaultProcessor();
selectorManager.setInetAddress(inetAddress);
selectorManager.setPort(port);
selectorManager.doPostInitializationTasks();
environment = new Environment(selectorManager, proc, randomSource, timeSource, logManager, parameters, exceptionStrategy);
// setup Log4j.xml watcher
DOMConfigurator.configureAndWatch(log4jFile.getAbsolutePath(), LOG4J_WATCHER_INTERVAL);
}
示例15: init
import org.apache.log4j.xml.DOMConfigurator; //导入方法依赖的package包/类
/**
* Starts the simulator feed (or connects to the external
* feed, for a real feed).
*/
public void init(Map params, File 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.StockQuotes");
//The feedMap of this adapter is never used
// Read the Adapter Set name, which is supplied by the Server as a parameter
String adapterSetId = (String) params.get("adapters_conf.id");
// Put a reference to this instance on a static map
// to be read by the Metadata Adapter
feedMap.put(adapterSetId, this);
myFeed.start();
logger.info("StockQuotesDataAdapter ready.");
}
开发者ID:Lightstreamer,项目名称:Lightstreamer-example-StockList-adapter-java,代码行数:28,代码来源:StockQuotesDataAdapter.java