1 /**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. 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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
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 }