1 /** 2 * 3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> 4 * 5 * ==================================================================== 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * ==================================================================== 18 */ 19 package org.jclouds.logging; 20 21 /** 22 * JCloud log abstraction layer. 23 * <p/> 24 * Implementations of logging are optional and injected if they are configured. 25 * <p/> 26 * <code> @Resource Logger logger = Logger.NULL;</code> The above will get you a null-safe instance 27 * of <tt>Logger</tt>. If configured, this logger will be swapped with a real Logger implementation 28 * with category set to the current class name. This is done post-object construction, so do not 29 * attempt to use these loggers in your constructor. 30 * <p/> 31 * If you wish to initialize loggers like these yourself, do not use the @Resource annotation. 32 * <p/> 33 * This implementation first checks to see if the level is enabled before issuing the log command. 34 * In other words, don't do the following 35 * <code>if (logger.isTraceEnabled()) logger.trace("message");. 36 * <p/> 37 * 38 * @author Adrian Cole 39 */ 40 public interface Logger { 41 42 /** 43 * Assign to member to avoid NPE when no logging module is configured. 44 */ 45 public static final Logger NULL = new NullLogger(); 46 47 /** 48 * Assign to member to avoid NPE when no logging module is configured. 49 */ 50 public static final Logger CONSOLE = new ConsoleLogger(); 51 52 String getCategory(); 53 54 void trace(String message, Object... args); 55 56 boolean isTraceEnabled(); 57 58 void debug(String message, Object... args); 59 60 boolean isDebugEnabled(); 61 62 void info(String message, Object... args); 63 64 boolean isInfoEnabled(); 65 66 void warn(String message, Object... args); 67 68 void warn(Throwable throwable, String message, Object... args); 69 70 boolean isWarnEnabled(); 71 72 void error(String message, Object... args); 73 74 void error(Throwable throwable, String message, Object... args); 75 76 boolean isErrorEnabled(); 77 78 /** 79 * Produces instances of {@link Logger} relevant to the specified category 80 * 81 * @author Adrian Cole 82 * 83 */ 84 public static interface LoggerFactory { 85 Logger getLogger(String category); 86 } 87 }