2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.logging.api;
25 * <a>Factory to hide a concrete, framework-specific implementation of logger creation.</a>
26 * <p>The service used by this factory must implement {@link LoggerCreationService}. If no
27 * implementation has been configured or could not be instantiated, a <b>no-op logger</b> will be
28 * used, and <b>no events</b> will be logged. This is done to prevent recursion if attempts are
29 * being made to log exceptions that resulted from logger initialization. </p>
33 * @see LoggerCreationService
36 @SuppressWarnings("ThrowableInstanceNeverThrown")
37 public class LoggerFactory extends BaseFactory {
39 private static final LoggerCreationService SERVICE;
42 LoggerCreationService service;
45 service = locateService(LoggerCreationService.class);
46 } catch (Exception ex) {
47 new RuntimeException("Failed to instantiate logger factory", ex).printStackTrace();
48 // use the no-op service to prevent recursion in case of an attempt to log an exception as a
49 // result of a logger initialization error
50 service = new NoOpLoggerCreationService();
56 public static Logger getLogger(String clazzName) {
57 return SERVICE.getLogger(clazzName);
60 public static Logger getLogger(Class<?> clazz) {
61 return SERVICE.getLogger(clazz);
64 private static class NoOpLoggerCreationService implements LoggerCreationService {
66 private static final Logger NO_OP_LOGGER = new Logger() {
69 public String getName() {
70 return "No-Op Logger";
74 public boolean isMetricsEnabled() {
79 public void metrics(String msg) {
83 public void metrics(String msg, Object arg) {
87 public void metrics(String msg, Object arg1, Object arg2) {
91 public void metrics(String msg, Object... arguments) {
95 public void metrics(String msg, Throwable t) {
99 public boolean isAuditEnabled() {
104 public void audit(String msg) {
108 public void audit(String msg, Object arg) {
112 public void audit(String msg, Object arg1, Object arg2) {
116 public void audit(String msg, Object... arguments) {
120 public void audit(String msg, Throwable t) {
124 public boolean isDebugEnabled() {
129 public void debug(String msg) {
133 public void debug(String msg, Object arg) {
137 public void debug(String msg, Object arg1, Object arg2) {
141 public void debug(String msg, Object... arguments) {
145 public void debug(String msg, Throwable t) {
149 public boolean isInfoEnabled() {
154 public void info(String msg) {
158 public void info(String msg, Object arg) {
162 public void info(String msg, Object arg1, Object arg2) {
166 public void info(String msg, Object... arguments) {
170 public void info(String msg, Throwable t) {
174 public boolean isWarnEnabled() {
179 public void warn(String msg) {
183 public void warn(String msg, Object arg) {
187 public void warn(String msg, Object... arguments) {
191 public void warn(String msg, Object arg1, Object arg2) {
195 public void warn(String msg, Throwable t) {
199 public boolean isErrorEnabled() {
204 public void error(String msg) {
208 public void error(String msg, Object arg) {
212 public void error(String msg, Object arg1, Object arg2) {
216 public void error(String msg, Object... arguments) {
220 public void error(String msg, Throwable t) {
225 public Logger getLogger(String className) {
230 public Logger getLogger(Class<?> clazz) {