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 | import com.google.common.base.Throwables; |
22 | |
23 | /** |
24 | * <tt>Logger</tt> that logs to the console |
25 | * <p /> |
26 | * Useful to get baseline performance unaffected by logging. |
27 | * |
28 | * @author Adrian Cole |
29 | * |
30 | */ |
31 | public class ConsoleLogger implements Logger { |
32 | |
33 | /** |
34 | * {@inheritDoc} |
35 | */ |
36 | @Override |
37 | public void debug(String message, Object... args) { |
38 | |
39 | } |
40 | |
41 | /** |
42 | * {@inheritDoc} |
43 | */ |
44 | @Override |
45 | public void error(String message, Object... args) { |
46 | System.err.printf(String.format("ERROR: %s%n", message), args); |
47 | } |
48 | |
49 | /** |
50 | * {@inheritDoc} |
51 | */ |
52 | @Override |
53 | public void error(Throwable throwable, String message, Object... args) { |
54 | System.err.printf(String.format("ERROR: %s%n%s", message, Throwables |
55 | .getStackTraceAsString(throwable)), args); |
56 | } |
57 | |
58 | /** |
59 | * {@inheritDoc} |
60 | */ |
61 | @Override |
62 | public String getCategory() { |
63 | return null; |
64 | } |
65 | |
66 | /** |
67 | * {@inheritDoc} |
68 | */ |
69 | @Override |
70 | public void info(String message, Object... args) { |
71 | System.err.printf(String.format("INFO: %s%n", message), args); |
72 | } |
73 | |
74 | /** |
75 | * {@inheritDoc} |
76 | */ |
77 | @Override |
78 | public boolean isDebugEnabled() { |
79 | return false; |
80 | } |
81 | |
82 | /** |
83 | * {@inheritDoc} |
84 | */ |
85 | @Override |
86 | public boolean isErrorEnabled() { |
87 | |
88 | return true; |
89 | } |
90 | |
91 | /** |
92 | * {@inheritDoc} |
93 | */ |
94 | @Override |
95 | public boolean isInfoEnabled() { |
96 | |
97 | return true; |
98 | } |
99 | |
100 | /** |
101 | * {@inheritDoc} |
102 | */ |
103 | @Override |
104 | public boolean isTraceEnabled() { |
105 | |
106 | return false; |
107 | } |
108 | |
109 | /** |
110 | * {@inheritDoc} |
111 | */ |
112 | @Override |
113 | public boolean isWarnEnabled() { |
114 | |
115 | return true; |
116 | } |
117 | |
118 | /** |
119 | * {@inheritDoc} |
120 | */ |
121 | @Override |
122 | public void trace(String message, Object... args) { |
123 | |
124 | } |
125 | |
126 | /** |
127 | * {@inheritDoc} |
128 | */ |
129 | @Override |
130 | public void warn(String message, Object... args) { |
131 | System.err.printf(String.format("WARN: %s%n", message), args); |
132 | } |
133 | |
134 | /** |
135 | * {@inheritDoc} |
136 | */ |
137 | @Override |
138 | public void warn(Throwable throwable, String message, Object... args) { |
139 | System.err.printf(String.format("WARN: %s%n%s", message, Throwables |
140 | .getStackTraceAsString(throwable)), args); |
141 | } |
142 | |
143 | } |