本文整理汇总了Java中org.apache.log4j.xml.DOMConfigurator类的典型用法代码示例。如果您正苦于以下问题:Java DOMConfigurator类的具体用法?Java DOMConfigurator怎么用?Java DOMConfigurator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DOMConfigurator类属于org.apache.log4j.xml包,在下文中一共展示了DOMConfigurator类的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: initializeLogger
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
public synchronized static void initializeLogger() {
if(isInitialized)
return;
InputStream configStream = null;
try {
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("log4j.xml");
if(configStream != null){
new DOMConfigurator().doConfigure(configStream, LogManager.getLoggerRepository());
} else {
System.out.println("Error reading log configurstion file. Could not initialize logger.");
}
} finally{
if(configStream != null){
try {
configStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
isInitialized = true;
}
示例3: init
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
private void init() {
try {
final VirtualFile logXml = LuaFileUtil.getPluginVirtualDirectoryChild("log.xml");
File logXmlFile = new File(logXml.getPath());
String text = FileUtil.loadFile(logXmlFile);
text = StringUtil.replace(text, SYSTEM_MACRO, StringUtil.replace(PathManager.getSystemPath(), "\\", "\\\\"));
text = StringUtil.replace(text, APPLICATION_MACRO, StringUtil.replace(PathManager.getHomePath(), "\\", "\\\\"));
text = StringUtil.replace(text, LOG_DIR_MACRO, StringUtil.replace(PathManager.getLogPath(), "\\", "\\\\"));
new DOMConfigurator().doConfigure(new StringReader(text), LogManager.getLoggerRepository());
}
catch (Exception e) {
e.printStackTrace();
}
}
示例4: 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);
}
}
示例5: loading
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
@Override
public void loading() throws AlbianServiceException {
try {
Thread.currentThread().setContextClassLoader(AlbianClassLoader.getInstance());
if (KernelSetting.getAlbianConfigFilePath().startsWith("http://")) {
DOMConfigurator.configure(new URL(Path
.getExtendResourcePath(KernelSetting
.getAlbianConfigFilePath() + "log4j.xml")));
} else {
DOMConfigurator.configure(Path
.getExtendResourcePath(KernelSetting
.getAlbianConfigFilePath() + "log4j.xml"));
}
super.loading();
loggers = new ConcurrentHashMap<String, Logger>();
// logger = LoggerFactory.getLogger(ALBIAN_LOGGER);
} catch (Exception exc) {
throw new AlbianServiceException(exc.getMessage(), exc.getCause());
}
}
示例6: 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);
}
}
示例7: 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));
}
}
示例8: main
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
public static void main(final String[] args) {
final String log4jConfiguration = System.getProperties().getProperty("log4j.configuration");
if (StringUtils.isNotBlank(log4jConfiguration)) {
final String parsedConfiguration = PathUtils.clean(StringUtils.removeStart(log4jConfiguration, "file:"));
final File configFile = new File(parsedConfiguration);
if (configFile.exists()) {
DOMConfigurator.configure(parsedConfiguration);
} else {
BasicConfigurator.configure();
}
}
log.info("Starting Copy Tool");
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> log.error("Uncaught exception in " + thread.getName(), throwable));
final CopyTool copyTool = new CopyTool();
final int returnCode = copyTool.setupAndRun(args);
log.info("Finished running Copy Tool");
System.exit(returnCode);
}
示例9: main
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
public static void main(final String[] args) {
final String log4jConfiguration = System.getProperties().getProperty("log4j.configuration");
if (StringUtils.isNotBlank(log4jConfiguration)) {
final String parsedConfiguration = PathUtils.clean(StringUtils.removeStart(log4jConfiguration, "file:"));
final File configFile = new File(parsedConfiguration);
if (configFile.exists()) {
DOMConfigurator.configure(parsedConfiguration);
} else {
BasicConfigurator.configure();
}
}
log.info("Starting Merge Tool");
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(final Thread thread, final Throwable throwable) {
log.error("Uncaught exception in " + thread.getName(), throwable);
}
});
final int returnCode = setupAndRun(args);
log.info("Finished running Merge Tool");
System.exit(returnCode);
}
示例10: common
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
void common(int number) throws Exception {
DOMConfigurator.configure("input/xml/customLogger"+number+".xml");
int i = -1;
Logger root = Logger.getRootLogger();
logger.trace("Message " + ++i);
logger.debug("Message " + ++i);
logger.warn ("Message " + ++i);
logger.error("Message " + ++i);
logger.fatal("Message " + ++i);
Exception e = new Exception("Just testing");
logger.debug("Message " + ++i, e);
Transformer.transform(
"output/temp", FILTERED,
new Filter[] {
new LineNumberFilter(), new SunReflectFilter(),
new JunitTestRunnerFilter()
});
assertTrue(Compare.compare(FILTERED, "witness/customLogger."+number));
}
示例11: test1
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
public void test1() throws Exception {
DOMConfigurator.configure("input/xml/fallback1.xml");
common();
ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT,
EXCEPTION1, EXCEPTION2, EXCEPTION3});
ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT,
EXCEPTION1, EXCEPTION2, EXCEPTION3});
Transformer.transform(TEMP_A1, FILTERED_A1, new Filter[] {cf1,
new LineNumberFilter()});
Transformer.transform(TEMP_A2, FILTERED_A2, new Filter[] {cf2,
new LineNumberFilter(), new ISO8601Filter()});
assertTrue(Compare.compare(FILTERED_A1, "witness/dom.A1.1"));
assertTrue(Compare.compare(FILTERED_A2, "witness/dom.A2.1"));
}
示例12: 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());
}
}
示例13: loadLog4JConfigXml
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
public static boolean loadLog4JConfigXml(File directory) {
File f = new File(directory, CONFIG_FILENAME);
if (!f.isFile())
return false;
try {
DOMConfigurator.configure(f.getAbsolutePath());
} catch (Exception e) {
System.err.println("Error loading log4j config file \"" + f.getAbsolutePath() + "\"");
return false;
}
Logger logger = Logger.getLogger("LogSystem");
logger.setLevel(Level.INFO);
logger.info("Logging configured by \"" + f.getAbsolutePath() + "\"");
CONFIGURED = true;
return true;
}
示例14: Log4JLogger
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
/**
* Creates new logger with given configuration {@code path}.
*
* @param path Path to log4j configuration XML file.
* @throws IgniteCheckedException Thrown in case logger can't be created.
*/
public Log4JLogger(final String path) throws IgniteCheckedException {
if (path == null)
throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
this.cfg = path;
final URL cfgUrl = U.resolveIgniteUrl(path);
if (cfgUrl == null)
throw new IgniteCheckedException("Log4j configuration path was not found: " + path);
addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
DOMConfigurator.configure(cfgUrl);
return Logger.getRootLogger();
}
});
quiet = quiet0;
}
示例15: GridTestLog4jLogger
import org.apache.log4j.xml.DOMConfigurator; //导入依赖的package包/类
/**
* Creates new logger with given configuration {@code path}.
*
* @param path Path to log4j configuration XML file.
* @throws IgniteCheckedException Thrown in case logger can't be created.
*/
public GridTestLog4jLogger(String path) throws IgniteCheckedException {
if (path == null)
throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
this.cfg = path;
final URL cfgUrl = U.resolveIgniteUrl(path);
if (cfgUrl == null)
throw new IgniteCheckedException("Log4j configuration path was not found: " + path);
addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
DOMConfigurator.configure(cfgUrl);
return Logger.getRootLogger();
}
});
quiet = quiet0;
}