1 /* 2 ~ Copyright 2006-2007 Nicolas De Loof. 3 ~ 4 ~ Licensed under the Apache License, Version 2.0 (the "License"); 5 ~ you may not use this file except in compliance with the License. 6 ~ You may obtain a copy of the License at 7 ~ 8 ~ http://www.apache.org/licenses/LICENSE-2.0 9 ~ 10 ~ Unless required by applicable law or agreed to in writing, software 11 ~ distributed under the License is distributed on an "AS IS" BASIS, 12 ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ~ See the License for the specific language governing permissions and 14 ~ limitations under the License. 15 */ 16 package org.jmonit.log; 17 18 import java.util.logging.Level; 19 20 /** 21 * Logger implementation based on Java 1.4+ logging API. 22 * 23 * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a> 24 */ 25 public class Java14Logger 26 extends Log 27 { 28 /** Delegate java 1.4 logger */ 29 private java.util.logging.Logger logger; 30 31 /** 32 * Constructor 33 * 34 * @param target logging class 35 */ 36 public Java14Logger( Class target ) 37 { 38 super(); 39 logger = java.util.logging.Logger.getLogger( target.getName() ); 40 } 41 42 /** 43 * {@inheritDoc} 44 * 45 * @see info.jmonit.logger.Log#debug(java.lang.String) 46 */ 47 public void debug( String message ) 48 { 49 logger.log( Level.FINE, message ); 50 } 51 52 /** 53 * {@inheritDoc} 54 * 55 * @see info.jmonit.logger.Log#info(java.lang.String) 56 */ 57 public void info( String message ) 58 { 59 logger.log( Level.INFO, message ); 60 } 61 62 /** 63 * {@inheritDoc} 64 * 65 * @see info.jmonit.logger.Log#info(java.lang.String, Throwable) 66 */ 67 public void info( String message, Throwable t ) 68 { 69 logger.log( Level.INFO, message, t ); 70 } 71 72 /** 73 * {@inheritDoc} 74 * 75 * @see info.jmonit.logger.Log#error(java.lang.String) 76 */ 77 public void error( String message ) 78 { 79 logger.log( Level.SEVERE, message ); 80 } 81 82 /** 83 * {@inheritDoc} 84 * 85 * @see info.jmonit.logger.Log#error(java.lang.String, Throwable) 86 */ 87 public void error( String message, Throwable t ) 88 { 89 logger.log( Level.SEVERE, message, t ); 90 } 91 92 /** 93 * {@inheritDoc} 94 * 95 * @see info.jmonit.logger.Log#isDebugEnabled() 96 */ 97 public boolean isDebugEnabled() 98 { 99 return logger.isLoggable( Level.FINE ); 100 } 101 102 /** 103 * {@inheritDoc} 104 * 105 * @see info.jmonit.logger.Log#warn(java.lang.String) 106 */ 107 public void warn( String message ) 108 { 109 logger.log( Level.WARNING, message ); 110 } 111 112 /** 113 * {@inheritDoc} 114 * 115 * @see info.jmonit.logger.Log#warn(java.lang.String, Throwable) 116 */ 117 public void warn( String message, Throwable t ) 118 { 119 logger.log( Level.WARNING, message, t ); 120 } 121 }