|
Apache CXF example source code file (Log4jLogger.java)
The Apache CXF Log4jLogger.java source code/** * 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.cxf.common.logging; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; import org.apache.log4j.Appender; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Priority; import org.apache.log4j.spi.LoggingEvent; /** * java.util.logging.Logger implementation delegating to Log4j. * All methods can be used except: * setLevel * addHandler / getHandlers * setParent / getParent * setUseParentHandlers / getUseParentHandlers * * @author gnodet */ public class Log4jLogger extends AbstractDelegatingLogger { private static final Map<Level, org.apache.log4j.Level> TO_LOG4J = new HashMap<Level, org.apache.log4j.Level>(); private static final org.apache.log4j.Level TRACE; private final org.apache.log4j.Logger log; static { JDKBugHacks.doHacks(); //older versions of log4j don't have TRACE, use debug org.apache.log4j.Level t = org.apache.log4j.Level.DEBUG; try { Field f = org.apache.log4j.Level.class.getField("TRACE"); t = (org.apache.log4j.Level)f.get(null); } catch (Exception ex) { //ignore, assume old version of log4j } TRACE = t; TO_LOG4J.put(Level.ALL, org.apache.log4j.Level.ALL); TO_LOG4J.put(Level.SEVERE, org.apache.log4j.Level.ERROR); TO_LOG4J.put(Level.WARNING, org.apache.log4j.Level.WARN); TO_LOG4J.put(Level.INFO, org.apache.log4j.Level.INFO); TO_LOG4J.put(Level.CONFIG, org.apache.log4j.Level.DEBUG); TO_LOG4J.put(Level.FINE, org.apache.log4j.Level.DEBUG); TO_LOG4J.put(Level.FINER, TRACE); TO_LOG4J.put(Level.FINEST, TRACE); TO_LOG4J.put(Level.OFF, org.apache.log4j.Level.OFF); } public Log4jLogger(String name, String resourceBundleName) { super(name, resourceBundleName); log = org.apache.log4j.LogManager.getLogger(name); } public Level getLevel() { org.apache.log4j.Level l = log.getEffectiveLevel(); if (l != null) { return fromL4J(l); } return null; } public void setLevel(Level newLevel) throws SecurityException { log.setLevel(TO_LOG4J.get(newLevel)); } public synchronized void addHandler(Handler handler) throws SecurityException { log.addAppender(new HandlerWrapper(handler)); } public synchronized void removeHandler(Handler handler) throws SecurityException { log.removeAppender("HandlerWrapper-" + handler.hashCode()); } public synchronized Handler[] getHandlers() { List<Handler> ret = new ArrayList Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF Log4jLogger.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.