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.jdk; |
20 | |
21 | import java.util.logging.Level; |
22 | |
23 | import org.jclouds.logging.BaseLogger; |
24 | import org.jclouds.logging.Logger; |
25 | |
26 | /** |
27 | * {@link java.util.logging.Logger} implementation of {@link Logger}. |
28 | * |
29 | * @author Adrian Cole |
30 | * |
31 | */ |
32 | public class JDKLogger extends BaseLogger { |
33 | private final java.util.logging.Logger logger; |
34 | |
35 | public static class JDKLoggerFactory implements LoggerFactory { |
36 | public Logger getLogger(String category) { |
37 | return new JDKLogger(java.util.logging.Logger.getLogger(category)); |
38 | } |
39 | } |
40 | |
41 | public JDKLogger(java.util.logging.Logger logger) { |
42 | this.logger = logger; |
43 | } |
44 | |
45 | @Override |
46 | protected void logTrace(String message) { |
47 | logger.finest(message); |
48 | } |
49 | |
50 | public boolean isTraceEnabled() { |
51 | return logger.isLoggable(Level.FINEST); |
52 | } |
53 | |
54 | @Override |
55 | protected void logDebug(String message) { |
56 | logger.fine(message); |
57 | } |
58 | |
59 | public boolean isDebugEnabled() { |
60 | return logger.isLoggable(Level.FINE); |
61 | } |
62 | |
63 | @Override |
64 | protected void logInfo(String message) { |
65 | logger.info(message); |
66 | } |
67 | |
68 | public boolean isInfoEnabled() { |
69 | return logger.isLoggable(Level.INFO); |
70 | } |
71 | |
72 | @Override |
73 | protected void logWarn(String message) { |
74 | logger.warning(message); |
75 | } |
76 | |
77 | @Override |
78 | protected void logWarn(String message, Throwable e) { |
79 | logger.log(Level.WARNING, message, e); |
80 | } |
81 | |
82 | public boolean isWarnEnabled() { |
83 | return logger.isLoggable(Level.WARNING); |
84 | } |
85 | |
86 | @Override |
87 | protected void logError(String message) { |
88 | logger.severe(message); |
89 | } |
90 | |
91 | @Override |
92 | protected void logError(String message, Throwable e) { |
93 | logger.log(Level.SEVERE, message, e); |
94 | } |
95 | |
96 | public boolean isErrorEnabled() { |
97 | return logger.isLoggable(Level.SEVERE); |
98 | } |
99 | |
100 | public String getCategory() { |
101 | return logger.getName(); |
102 | } |
103 | } |