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 java.text.MessageFormat;
import java.util.MissingResourceException;
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 void configure() {
//See if user factory has been specified
final String factoryName = System.getProperty("openejb.log.factory");
if (factoryName != null) {
Class factoryClass = null;
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) {
try {
factoryClass = classLoader.loadClass(factoryName);
} catch (Throwable e) {
//Ignore
}
}
if (factoryClass == null) {
try {
factoryClass = Class.forName(factoryName);
} catch (Throwable e) {
//Ignore
}
}
if (factoryClass != null) {
try {
//Try and use the user specified factory
logStreamFactory = (LogStreamFactory) factoryClass.newInstance();
return;
} catch (Throwable e) {
//Ignore
}
}
}
// See if log4j is available
Log4jLogStreamFactory log4jLogStreamFactory = null;
try {
Logger.class.getClassLoader().loadClass("org.apache.log4j.Layout");
if (!System.getProperties().containsKey("org.apache.cxf.Logger")) {
System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger");
}
//This will configure log4j, but we may be using slf4j later
log4jLogStreamFactory = new Log4jLogStreamFactory();
} catch (Throwable e) {
//Ignore
}
// Fall back to JUL if log4j is not available
JuliLogStreamFactory juliLogStreamFactory = null;
if (null == log4jLogStreamFactory) {
//This will configure JUL, but we may be using slf4j later
juliLogStreamFactory = new JuliLogStreamFactory();
}
// See if slf4j is available
try {
Logger.class.getClassLoader().loadClass("org.slf4j.LoggerFactory");
if (!System.getProperties().containsKey("org.apache.cxf.Logger")) {
System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Slf4jLogger");
}
//This will delegate to either log4j or JUL
logStreamFactory = new Slf4jLogStreamFactory();
return;
} catch (Throwable e) {
//Ignore
}
//Fall back to either log4j or JUL
logStreamFactory = (null != log4jLogStreamFactory ? log4jLogStreamFactory : juliLogStreamFactory);
}
/**
* 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(String key) throws InterruptedException {
int index = key.lastIndexOf(".");
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(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