001package org.apache.turbine.services.avaloncomponent; 002 003import org.apache.avalon.framework.logger.Logger; 004import org.apache.logging.log4j.LogManager; 005 006/* 007 * Licensed to the Apache Software Foundation (ASF) under one or more 008 * contributor license agreements. See the NOTICE file distributed with 009 * this work for additional information regarding copyright ownership. 010 * The ASF licenses this file to You under the Apache License, Version 2.0 011 * (the "License"); you may not use this file except in compliance with 012 * the License. You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an "AS IS" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 */ 022 023/** 024 * A Log4J2 wrapper class for Logger. 025 * 026 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a> 027 */ 028public final class Log4j2Logger 029 implements Logger 030{ 031 // underlying implementation 032 private final org.apache.logging.log4j.Logger m_logger; 033 034 /** 035 * Create a logger that delegates to specified category. 036 * 037 * @param logImpl 038 * the category to delegate to 039 */ 040 public Log4j2Logger(final org.apache.logging.log4j.Logger logImpl) 041 { 042 m_logger = logImpl; 043 } 044 045 /** 046 * Log a debug message. 047 * 048 * @param message 049 * the message 050 */ 051 @Override 052 public void debug(final String message) 053 { 054 m_logger.debug(message); 055 } 056 057 /** 058 * Log a debug message. 059 * 060 * @param message 061 * the message 062 * @param throwable 063 * the throwable 064 */ 065 @Override 066 public void debug(final String message, final Throwable throwable) 067 { 068 m_logger.debug(message, throwable); 069 } 070 071 /** 072 * Determine if messages of priority "debug" will be logged. 073 * 074 * @return true if "debug" messages will be logged 075 */ 076 @Override 077 public boolean isDebugEnabled() 078 { 079 return m_logger.isDebugEnabled(); 080 } 081 082 /** 083 * Log a info message. 084 * 085 * @param message 086 * the message 087 */ 088 @Override 089 public void info(final String message) 090 { 091 m_logger.info(message); 092 } 093 094 /** 095 * Log a info message. 096 * 097 * @param message 098 * the message 099 * @param throwable 100 * the throwable 101 */ 102 @Override 103 public void info(final String message, final Throwable throwable) 104 { 105 m_logger.info(message, throwable); 106 } 107 108 /** 109 * Determine if messages of priority "info" will be logged. 110 * 111 * @return true if "info" messages will be logged 112 */ 113 @Override 114 public boolean isInfoEnabled() 115 { 116 return m_logger.isInfoEnabled(); 117 } 118 119 /** 120 * Log a warn message. 121 * 122 * @param message 123 * the message 124 */ 125 @Override 126 public void warn(final String message) 127 { 128 m_logger.warn(message); 129 } 130 131 /** 132 * Log a warn message. 133 * 134 * @param message 135 * the message 136 * @param throwable 137 * the throwable 138 */ 139 @Override 140 public void warn(final String message, final Throwable throwable) 141 { 142 m_logger.warn(message, throwable); 143 } 144 145 /** 146 * Determine if messages of priority "warn" will be logged. 147 * 148 * @return true if "warn" messages will be logged 149 */ 150 @Override 151 public boolean isWarnEnabled() 152 { 153 return m_logger.isWarnEnabled(); 154 } 155 156 /** 157 * Log a error message. 158 * 159 * @param message 160 * the message 161 */ 162 @Override 163 public void error(final String message) 164 { 165 m_logger.error(message); 166 } 167 168 /** 169 * Log a error message. 170 * 171 * @param message 172 * the message 173 * @param throwable 174 * the throwable 175 */ 176 @Override 177 public void error(final String message, final Throwable throwable) 178 { 179 m_logger.error(message, throwable); 180 } 181 182 /** 183 * Determine if messages of priority "error" will be logged. 184 * 185 * @return true if "error" messages will be logged 186 */ 187 @Override 188 public boolean isErrorEnabled() 189 { 190 return m_logger.isErrorEnabled(); 191 } 192 193 /** 194 * Log a fatalError message. 195 * 196 * @param message 197 * the message 198 */ 199 @Override 200 public void fatalError(final String message) 201 { 202 m_logger.fatal(message); 203 } 204 205 /** 206 * Log a fatalError message. 207 * 208 * @param message 209 * the message 210 * @param throwable 211 * the throwable 212 */ 213 @Override 214 public void fatalError(final String message, final Throwable throwable) 215 { 216 m_logger.fatal(message, throwable); 217 } 218 219 /** 220 * Determine if messages of priority "fatalError" will be logged. 221 * 222 * @return true if "fatalError" messages will be logged 223 */ 224 @Override 225 public boolean isFatalErrorEnabled() 226 { 227 return m_logger.isFatalEnabled(); 228 } 229 230 /** 231 * Create a new child logger. The name of the child logger is 232 * [current-loggers-name].[passed-in-name] Throws 233 * <code>IllegalArgumentException</code> if name has an empty element name 234 * 235 * @param name 236 * the subname of this logger 237 * @return the new logger 238 */ 239 @Override 240 public Logger getChildLogger(final String name) 241 { 242 return new Log4j2Logger(LogManager.getLogger(m_logger.getName() + "." + name)); 243 } 244}