Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openejb.util;
import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.SystemInstance;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
public class Logger {
private static final String SUFFIX = ".Messages";
private static final String OPENEJB = "org.apache.openejb";
private static LogStreamFactory logStreamFactory;
static {
configure();
}
public static synchronized void configure() {
if (logStreamFactory != null) {
return;
}
//See if user factory has been specified
String factoryName = SystemInstance.get().getOptions().get("openejb.log.factory", JuliLogStreamFactory.class.getName());
if ("jul".equalsIgnoreCase(factoryName) || "juli".equalsIgnoreCase(factoryName)) {
factoryName = JuliLogStreamFactory.class.getName();
} else if ("slf4j".equalsIgnoreCase(factoryName)) {
factoryName = Slf4jLogStreamFactory.class.getName();
} else if ("log4j".equalsIgnoreCase(factoryName)) {
if (exists("org.apache.log4j.Logger")) {
// don't use .class to avoid to force loading since log4j is not mandatory
factoryName = "org.apache.openejb.util.Log4jLogStreamFactory";
} else {
System.out.println("Cannot respect 'openejb.log.factory=log4j' setting as Log4j is not in the classpath.");
}
} else if ("pax".equalsIgnoreCase(factoryName)) {
factoryName = "org.apache.openejb.util.PaxLogStreamFactory";
}
if (factoryName != null) {
logStreamFactory = createFactory(factoryName);
}
if (isLog4jImplied()) {
logStreamFactory = createFactory("org.apache.openejb.util.Log4jLogStreamFactory");
}
//Fall back -> JUL
if (logStreamFactory == null) {
logStreamFactory = new JuliLogStreamFactory();
}
checkForIgnoredLog4jConfig();
}
private static void checkForIgnoredLog4jConfig() {
if (logStreamFactory.getClass().getName().equals("org.apache.openejb.util.Log4jLogStreamFactory")) return;
try {
final Properties configFile = log4j(loadLoggingProperties());
final Properties systemProperties = log4j(SystemInstance.get().getProperties());
if (configFile.size() == 0 && systemProperties.size() == 0) return;
final LogStream stream = logStreamFactory.createLogStream(LogCategory.OPENEJB);
stream.warn("Log4j not installed. The following properties will be ignored.");
final String format = "Ignored %s property '%s'";
for (final Object key : configFile.keySet()) {
stream.warn(String.format(format, "conf/logging.properties", key));
}
for (final Object key : systemProperties.keySet()) {
stream.warn(String.format(format, "Property overrides", key));
}
} catch (Throwable e) {
// added strong catch block just in case
// This check is only a convenience
}
}
private static LogStreamFactory createFactory(final String factoryName) {
final Class> factoryClass = load(factoryName);
if (factoryClass == null) return null;
try {
//Try and use the user specified factory
return (LogStreamFactory) factoryClass.newInstance();
} catch (Throwable e) {
//Ignore
}
return null;
}
private static Class> load(final String factoryName) {
try {
final ClassLoader classLoader = Logger.class.getClassLoader();
return classLoader.loadClass(factoryName);
} catch (Throwable e) {
//Ignore
}
try {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
return contextClassLoader.loadClass(factoryName);
} catch (Throwable e1) {
//Ignore
}
try {
return Class.forName(factoryName);
} catch (Throwable e2) {
//Ignore
}
return null;
}
/**
* Computes the parent of a resource name. E.g. if we pass in a key of
* a.b.c, it returns the value a.b
*/
private static final Computable heirarchyResolver = new Computable() {
@Override
public String compute(final String key) throws InterruptedException {
final int index = key.lastIndexOf(".");
final String parent = key.substring(0, index);
if (parent.contains(OPENEJB))
return parent;
return null;
}
};
/**
* Simply returns the ResourceBundle for a given baseName
*/
private static final Computable bundleResolver = new Computable() {
@Override
public ResourceBundle compute(final String baseName) throws InterruptedException {
try {
return ResourceBundle.getBundle(baseName + SUFFIX);
} catch (MissingResourceException e) {
return null;
}
}
};
/**
* Builds a Logger object and returns it
*/
private static final Computable