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 {
62 private static final Logger NO_OP_LOGGER = new Logger() {
65 public String getName() {
66 return "No-Op Logger";
70 public boolean isMetricsEnabled() {
75 public void metrics(String msg) {
79 public void metrics(String msg, Object arg) {
83 public void metrics(String msg, Object arg1, Object arg2) {
87 public void metrics(String msg, Object... arguments) {
91 public void metrics(String msg, Throwable t) {
95 public boolean isAuditEnabled() {
100 public void audit(String msg) {
104 public void audit(String msg, Object arg) {
108 public void audit(String msg, Object arg1, Object arg2) {
112 public void audit(String msg, Object... arguments) {
116 public void audit(String msg, Throwable t) {
120 public boolean isDebugEnabled() {
125 public void debug(String msg) {
129 public void debug(String msg, Object arg) {
133 public void debug(String msg, Object arg1, Object arg2) {
137 public void debug(String msg, Object... arguments) {
141 public void debug(String msg, Throwable t) {
145 public boolean isInfoEnabled() {
150 public void info(String msg) {
154 public void info(String msg, Object arg) {
158 public void info(String msg, Object arg1, Object arg2) {
162 public void info(String msg, Object... arguments) {
166 public void info(String msg, Throwable t) {
170 public boolean isWarnEnabled() {
175 public void warn(String msg) {
179 public void warn(String msg, Object arg) {
183 public void warn(String msg, Object... arguments) {
187 public void warn(String msg, Object arg1, Object arg2) {
191 public void warn(String msg, Throwable t) {
195 public boolean isErrorEnabled() {
200 public void error(String msg) {
204 public void error(String msg, Object arg) {
208 public void error(String msg, Object arg1, Object arg2) {
212 public void error(String msg, Object... arguments) {
216 public void error(String msg, Throwable t) {
221 public Logger getLogger(String className) {
226 public Logger getLogger(Class<?> clazz) {