2 * Copyright © 2016-2018 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;
19 import java.util.Objects;
20 import org.openecomp.sdc.logging.spi.LoggerCreationService;
23 * <a>Factory to hide a concrete, framework-specific implementation of logger creation.</a>
24 * <p>The service used by this factory must implement {@link LoggerCreationService}. If no
25 * implementation has been configured or could be instantiated, a <b>no-op logger</b> will be
26 * used, and <b>no events</b> will be logged. This is done to prevent recursion if attempts are
27 * being made to log exceptions that resulted from logger initialization. </p>
33 * @see LoggerCreationService
35 public class LoggerFactory {
37 // use the no-op service to prevent recursion in case of an attempt to log an exception as a
38 // result of a logger initialization error
39 private static final LoggerCreationService SERVICE = ServiceBinder.getCreationServiceBinding().orElseGet(
40 NoOpLoggerCreationService::new);
42 private LoggerFactory() {
43 // prevent instantiation
46 public static Logger getLogger(String clazzName) {
47 return SERVICE.getLogger(clazzName);
50 public static Logger getLogger(Class<?> clazz) {
51 return SERVICE.getLogger(clazz);
54 private static class NoOpLoggerCreationService implements LoggerCreationService {
56 private static class NoOpLogger implements Logger {
58 private static final Logger INSTANCE = new NoOpLogger();
61 public String getName() {
62 return "No-Op Logger";
66 public boolean isMetricsEnabled() {
71 public void metrics(MetricsData msg) {
76 public void metrics(String msg) {
81 public boolean isAuditEnabled() {
86 public void auditEntry(AuditData data) {
91 public void auditExit(AuditData data) {
96 public boolean isDebugEnabled() {
101 public void debug(String msg) {
106 public void debug(String msg, Object arg) {
111 public void debug(String msg, Object arg1, Object arg2) {
116 public void debug(String msg, Object... arguments) {
121 public void debug(String msg, Throwable t) {
126 public boolean isInfoEnabled() {
131 public void info(String msg) {
136 public void info(String msg, Object arg) {
141 public void info(String msg, Object arg1, Object arg2) {
146 public void info(String msg, Object... arguments) {
151 public void info(String msg, Throwable t) {
156 public boolean isWarnEnabled() {
161 public void warn(String msg) {
166 public void warn(String msg, Object arg) {
171 public void warn(String msg, Object... arguments) {
176 public void warn(String msg, Object arg1, Object arg2) {
181 public void warn(String msg, Throwable t) {
186 public boolean isErrorEnabled() {
191 public void error(String msg) {
196 public void error(String msg, Object arg) {
201 public void error(String msg, Object arg1, Object arg2) {
206 public void error(String msg, Object... arguments) {
211 public void error(String msg, Throwable t) {
217 public Logger getLogger(String className) {
218 Objects.requireNonNull(className, "Name cannot be null");
219 return NoOpLogger.INSTANCE;
223 public Logger getLogger(Class<?> clazz) {
224 Objects.requireNonNull(clazz, "Class cannot be null");
225 return NoOpLogger.INSTANCE;