2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.logging.api;
21 * <a>Factory to hide a concrete, framework-specific implementation of logger creation.</a>
22 * <p>The service used by this factory must implement {@link LoggerCreationService}. If no
23 * implementation has been configured or could not be instantiated, a <b>no-op logger</b> will be
24 * used, and <b>no events</b> will be logged. This is done to prevent recursion if attempts are
25 * being made to log exceptions that resulted from logger initialization. </p>
29 * @see LoggerCreationService
32 @SuppressWarnings("ThrowableInstanceNeverThrown")
33 public class LoggerFactory extends BaseFactory {
35 private static final LoggerCreationService SERVICE;
38 LoggerCreationService service;
41 service = locateService(LoggerCreationService.class);
42 } catch (Exception ex) {
43 new RuntimeException("Failed to instantiate logger factory", ex).printStackTrace();
44 // use the no-op service to prevent recursion in case of an attempt to log an exception as a
45 // result of a logger initialization error
46 service = new NoOpLoggerCreationService();
52 public static Logger getLogger(String clazzName) {
53 return SERVICE.getLogger(clazzName);
56 public static Logger getLogger(Class<?> clazz) {
57 return SERVICE.getLogger(clazz);
60 private static class NoOpLoggerCreationService implements LoggerCreationService {
61 private static final Logger NO_OP_LOGGER = new NoOpLogger();
63 private static class NoOpLogger implements Logger {
65 public String getName() {
66 return "No-Op Logger";
70 public boolean isMetricsEnabled() {
75 public void metrics(String msg) {
76 //this is no_op_method
80 public void metrics(String msg, Object arg) {
81 //this is no_op_method
85 public void metrics(String msg, Object arg1, Object arg2) {
86 //this is no_op_method
90 public void metrics(String msg, Object... arguments) {
91 //this is no_op_method
95 public void metrics(String msg, Throwable t) {
96 //this is no_op_method
100 public boolean isAuditEnabled() {
105 public void audit(String msg) {
106 //this is no_op_method
110 public void audit(String msg, Object arg) {
111 //this is no_op_method
115 public void audit(String msg, Object arg1, Object arg2) {
116 //this is no_op_method
120 public void audit(String msg, Object... arguments) {
121 //this is no_op_method
125 public void audit(String msg, Throwable t) {
126 //this is no_op_method
130 public boolean isDebugEnabled() {
135 public void debug(String msg) {
136 //this is no_op_method
140 public void debug(String msg, Object arg) {
141 //this is no_op_method
145 public void debug(String msg, Object arg1, Object arg2) {
146 //this is no_op_method
150 public void debug(String msg, Object... arguments) {
151 //this is no_op_method
155 public void debug(String msg, Throwable t) {
156 //this is no_op_method
160 public boolean isInfoEnabled() {
165 public void info(String msg) {
166 //this is no_op_method
170 public void info(String msg, Object arg) {
171 //this is no_op_method
175 public void info(String msg, Object arg1, Object arg2) {
176 //this is no_op_method
180 public void info(String msg, Object... arguments) {
181 //this is no_op_method
185 public void info(String msg, Throwable t) {
186 //this is no_op_method
190 public boolean isWarnEnabled() {
195 public void warn(String msg) {
196 //this is no_op_method
200 public void warn(String msg, Object arg) {
201 //this is no_op_method
205 public void warn(String msg, Object... arguments) {
206 //this is no_op_method
210 public void warn(String msg, Object arg1, Object arg2) {
211 //this is no_op_method
215 public void warn(String msg, Throwable t) {
216 //this is no_op_method
220 public boolean isErrorEnabled() {
225 public void error(String msg) {
226 //this is no_op_method
230 public void error(String msg, Object arg) {
231 //this is no_op_method
235 public void error(String msg, Object arg1, Object arg2) {
236 //this is no_op_method
240 public void error(String msg, Object... arguments) {
241 //this is no_op_method
245 public void error(String msg, Throwable t) {
246 //this is no_op_method
251 public Logger getLogger(String className) {
256 public Logger getLogger(Class<?> clazz) {