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 org.openecomp.sdc.logging.spi.LoggerCreationService;
21 import java.util.Objects;
24 * <a>Factory to hide a concrete, framework-specific implementation of logger creation.</a>
25 * <p>The service used by this factory must implement {@link LoggerCreationService}. If no
26 * implementation has been configured or could be instantiated, a <b>no-op logger</b> will be
27 * used, and <b>no events</b> will be logged. This is done to prevent recursion if attempts are
28 * being made to log exceptions that resulted from logger initialization. </p>
34 * @see LoggerCreationService
36 public class LoggerFactory {
38 // use the no-op service to prevent recursion in case of an attempt to log an exception as a
39 // result of a logger initialization error
40 private static final LoggerCreationService SERVICE = ServiceBinder.getCreationServiceBinding().orElse(
41 new NoOpLoggerCreationService());
43 private LoggerFactory() {
44 // prevent instantiation
47 public static Logger getLogger(String clazzName) {
48 return SERVICE.getLogger(clazzName);
51 public static Logger getLogger(Class<?> clazz) {
52 return SERVICE.getLogger(clazz);
55 private static class NoOpLoggerCreationService implements LoggerCreationService {
57 private static final Logger NO_OP_LOGGER = new NoOpLogger();
59 private static class NoOpLogger implements Logger {
62 public String getName() {
63 return "No-Op Logger";
67 public boolean isMetricsEnabled() {
72 public void metrics(String msg) {
77 public void metrics(String msg, Object arg) {
82 public void metrics(String msg, Object arg1, Object arg2) {
87 public void metrics(String msg, Object... arguments) {
92 public void metrics(String msg, Throwable t) {
97 public boolean isAuditEnabled() {
102 public void audit(AuditData data) {
107 public boolean isDebugEnabled() {
112 public void debug(String msg) {
117 public void debug(String msg, Object arg) {
122 public void debug(String msg, Object arg1, Object arg2) {
127 public void debug(String msg, Object... arguments) {
132 public void debug(String msg, Throwable t) {
137 public boolean isInfoEnabled() {
142 public void info(String msg) {
147 public void info(String msg, Object arg) {
152 public void info(String msg, Object arg1, Object arg2) {
157 public void info(String msg, Object... arguments) {
162 public void info(String msg, Throwable t) {
167 public boolean isWarnEnabled() {
172 public void warn(String msg) {
177 public void warn(String msg, Object arg) {
182 public void warn(String msg, Object... arguments) {
187 public void warn(String msg, Object arg1, Object arg2) {
192 public void warn(String msg, Throwable t) {
197 public boolean isErrorEnabled() {
202 public void error(String msg) {
207 public void error(String msg, Object arg) {
212 public void error(String msg, Object arg1, Object arg2) {
217 public void error(String msg, Object... arguments) {
222 public void error(String msg, Throwable t) {
228 public Logger getLogger(String className) {
229 Objects.requireNonNull(className, "Name cannot be null");
234 public Logger getLogger(Class<?> clazz) {
235 Objects.requireNonNull(clazz, "Class cannot be null");