1 29 package net.sourceforge.groboutils.autodoc.v1.log4j; 30 31 32 import net.sourceforge.groboutils.autodoc.v1.AutoDocLog; 33 34 import org.apache.log4j.Logger; 35 import org.apache.log4j.Priority; 36 37 38 48 public class Log4jLog implements AutoDocLog 49 { 50 private Logger log; 51 52 53 60 public Log4jLog( Class owner ) 61 { 62 if (owner == null) 63 { 64 throw new IllegalArgumentException ("no null arguments"); 65 } 66 setLog( Logger.getLogger( owner ) ); 67 } 68 69 70 77 public Log4jLog( Logger log ) 78 { 79 setLog( log ); 80 } 81 82 83 public void debug( Object message ) 84 { 85 this.log.debug( message ); 86 } 87 88 public void debug( Object message[] ) 89 { 90 if (this.log.isDebugEnabled()) 91 { 92 this.log.debug( concatMessage( message ) ); 93 } 94 } 95 96 public void debug( Object message, Throwable error ) 97 { 98 this.log.debug( message, error ); 99 } 100 101 public void debug( Object message[], Throwable error ) 102 { 103 if (this.log.isDebugEnabled()) 104 { 105 this.log.debug( concatMessage( message ), error ); 106 } 107 } 108 109 public void info( Object message ) 110 { 111 this.log.info( message ); 112 } 113 114 public void info( Object message[] ) 115 { 116 if (this.log.isInfoEnabled()) 117 { 118 this.log.info( concatMessage( message ) ); 119 } 120 } 121 122 public void info( Object message, Throwable error ) 123 { 124 this.log.info( message, error ); 125 } 126 127 public void info( Object message[], Throwable error ) 128 { 129 if (this.log.isInfoEnabled()) 130 { 131 Object msg = concatMessage( message ); 132 this.log.info( msg, error ); 133 } 134 } 135 136 public void warn( Object message ) 137 { 138 this.log.warn( message ); 139 } 140 141 public void warn( Object message[] ) 142 { 143 if (this.log.isEnabledFor( Priority.WARN )) 144 { 145 this.log.warn( concatMessage( message ) ); 146 } 147 } 148 149 public void warn( Object message, Throwable error ) 150 { 151 this.log.warn( message, error ); 152 } 153 154 public void warn( Object message[], Throwable error ) 155 { 156 if (this.log.isEnabledFor( Priority.WARN )) 157 { 158 this.log.warn( concatMessage( message ), error ); 159 } 160 } 161 162 163 174 protected Object concatMessage( Object o[] ) 175 { 176 if (o == null) 177 { 178 return "null"; 179 } 180 if (o.length <= 0) 181 { 182 return ""; 183 } 184 StringBuffer sb = new StringBuffer (); 185 for (int i = 0; i < o.length; ++i) 186 { 187 sb.append( o[i] ); 188 } 189 return sb; 190 } 191 192 193 199 protected void setLog( Logger log ) 200 { 201 if (log == null) 202 { 203 throw new IllegalArgumentException ("no null arguments"); 204 } 205 this.log = log; 206 } 207 } 208 209 | Popular Tags |