1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 18 package org.apache.logging.log4j.jul; 19 20 import java.util.logging.Level; 21 import java.util.logging.Logger; 22 23 /** 24 * Log4j Core implementation of the JUL {@link Logger} class. <strong>Note that this implementation does 25 * <em>not</em> use the {@link java.util.logging.Handler} class.</strong> Instead, logging is delegated to the 26 * underlying Log4j {@link org.apache.logging.log4j.core.Logger} which uses 27 * {@link org.apache.logging.log4j.core.Appender Appenders} instead. 28 * 29 * @since 2.1 30 */ 31 public class CoreLogger extends ApiLogger { 32 33 private final org.apache.logging.log4j.core.Logger logger; 34 35 /** 36 * Constructs a Logger using a Log4j {@link org.apache.logging.log4j.core.Logger}. 37 * 38 * @param logger the underlying Logger to base this Logger on 39 */ 40 CoreLogger(final org.apache.logging.log4j.core.Logger logger) { 41 super(logger); 42 this.logger = logger; 43 } 44 45 @Override 46 public void setLevel(final Level level) throws SecurityException { 47 logger.setLevel(LevelTranslator.toLevel(level)); 48 super.doSetLevel(level); 49 } 50 51 /** 52 * Marks the underlying {@link org.apache.logging.log4j.core.Logger} as additive. 53 * 54 * @param additive {@code true} if this Logger should be additive 55 * @see org.apache.logging.log4j.core.Logger#setAdditive(boolean) 56 */ 57 @Override 58 public synchronized void setUseParentHandlers(final boolean additive) { 59 logger.setAdditive(additive); 60 } 61 62 /** 63 * Indicates if the underlying {@link org.apache.logging.log4j.core.Logger} is additive. <strong>Note that the 64 * Log4j version of JDK Loggers do <em>not</em> use Handlers.</strong> 65 * 66 * @return {@code true} if this Logger is additive, or {@code false} otherwise 67 * @see org.apache.logging.log4j.core.Logger#isAdditive() 68 */ 69 @Override 70 public synchronized boolean getUseParentHandlers() { 71 return logger.isAdditive(); 72 } 73 74 @Override 75 public Logger getParent() { 76 final org.apache.logging.log4j.core.Logger parent = logger.getParent(); 77 return parent == null ? null : Logger.getLogger(parent.getName()); 78 } 79 }