001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * Granite Data Services is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * Granite Data Services is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 020 * USA, or see <http://www.gnu.org/licenses/>. 021 */ 022package org.granite.logging; 023 024import org.apache.log4j.Level; 025import org.apache.log4j.LogManager; 026 027/** 028 * @author Franck WOLFF 029 */ 030public class Log4jLogger extends Logger { 031 032 /////////////////////////////////////////////////////////////////////////// 033 // Fields. 034 035 private static final String FQCN = Log4jLogger.class.getName(); 036 037 /////////////////////////////////////////////////////////////////////////// 038 // Constructor. 039 040 public Log4jLogger(String name, LoggingFormatter formatter) { 041 super(LogManager.getLogger(name), formatter); 042 } 043 044 /////////////////////////////////////////////////////////////////////////// 045 // Utility getter. 046 047 @Override 048 protected org.apache.log4j.Logger getLoggerImpl() { 049 return (org.apache.log4j.Logger)super.getLoggerImpl(); 050 } 051 052 /////////////////////////////////////////////////////////////////////////// 053 // Logging methods. 054 055 @Override 056 public void info(String message, Object... args) { 057 if (isInfoEnabled()) 058 getLoggerImpl().log(FQCN, Level.INFO, getFormatter().format(message, args), null); 059 } 060 061 @Override 062 public void info(Throwable t, String message, Object... args) { 063 if (isInfoEnabled()) 064 getLoggerImpl().log(FQCN, Level.INFO, getFormatter().format(message, args), t); 065 } 066 067 @Override 068 public void trace(String message, Object... args) { 069 if (isTraceEnabled()) 070 getLoggerImpl().log(FQCN, Level.TRACE, getFormatter().format(message, args), null); 071 } 072 073 @Override 074 public void trace(Throwable t, String message, Object... args) { 075 if (isTraceEnabled()) 076 getLoggerImpl().log(FQCN, Level.TRACE, getFormatter().format(message, args), t); 077 } 078 079 @Override 080 public void warn(String message, Object... args) { 081 if (isWarnEnabled()) 082 getLoggerImpl().log(FQCN, Level.WARN, getFormatter().format(message, args), null); 083 } 084 085 @Override 086 public void warn(Throwable t, String message, Object... args) { 087 if (isWarnEnabled()) 088 getLoggerImpl().log(FQCN, Level.WARN, getFormatter().format(message, args), t); 089 } 090 091 @Override 092 public void debug(String message, Object... args) { 093 if (isDebugEnabled()) 094 getLoggerImpl().log(FQCN, Level.DEBUG, getFormatter().format(message, args), null); 095 } 096 097 @Override 098 public void debug(Throwable t, String message, Object... args) { 099 if (isDebugEnabled()) 100 getLoggerImpl().log(FQCN, Level.DEBUG, getFormatter().format(message, args), t); 101 } 102 103 @Override 104 public void error(String message, Object... args) { 105 if (isErrorEnabled()) 106 getLoggerImpl().log(FQCN, Level.ERROR, getFormatter().format(message, args), null); 107 } 108 109 @Override 110 public void error(Throwable t, String message, Object... args) { 111 if (isErrorEnabled()) 112 getLoggerImpl().log(FQCN, Level.ERROR, getFormatter().format(message, args), t); 113 } 114 115 /////////////////////////////////////////////////////////////////////////// 116 // Configuration. 117 118 @Override 119 public boolean isDebugEnabled() { 120 return getLoggerImpl().isEnabledFor(Level.DEBUG); 121 } 122 123 @Override 124 public boolean isErrorEnabled() { 125 return getLoggerImpl().isEnabledFor(Level.ERROR); 126 } 127 128 @Override 129 public boolean isFatalEnabled() { 130 return getLoggerImpl().isEnabledFor(Level.FATAL); 131 } 132 133 @Override 134 public boolean isInfoEnabled() { 135 return getLoggerImpl().isEnabledFor(Level.INFO); 136 } 137 138 @Override 139 public boolean isTraceEnabled() { 140 return getLoggerImpl().isEnabledFor(Level.TRACE); 141 } 142 143 @Override 144 public boolean isWarnEnabled() { 145 return getLoggerImpl().isEnabledFor(Level.WARN); 146 } 147}