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.core.logging.api;
24 * <a>Factory to hide a concrete, framework-specific implementation of logger creation.</a> <p>The
25 * service used by this factory must implement {@link LoggerCreationService}. If no implementation
26 * has been configured or could not be instantiated, a <b>no-op logger</b> will be used, and <b>no
27 * events</b> will be logged. This is done to prevent recursion if attempts are being made to log
28 * exceptions that resulted from logger initialization. </p>
31 * @see LoggerCreationService
33 @SuppressWarnings("ThrowableInstanceNeverThrown")
34 public class LoggerFactory extends BaseFactory {
36 private static final LoggerCreationService SERVICE;
40 LoggerCreationService service;
43 service = locateService(LoggerCreationService.class);
44 } catch (Throwable throwable) {
45 new RuntimeException("Failed to instantiate logger factory", throwable).printStackTrace();
46 // use the no-op service to prevent recursion in case of an attempt to log an exception as a
47 // result of a logger initialization error
48 service = new NoOpLoggerCreationService();
54 public static Logger getLogger(String clazzName) {
55 return SERVICE.getLogger(clazzName);
58 public static Logger getLogger(Class<?> clazz) {
59 return SERVICE.getLogger(clazz);
62 private static class NoOpLoggerCreationService implements LoggerCreationService {
64 private static final Logger NO_OP_LOGGER = new Logger() {
67 public String getName() {
68 return "No-Op Logger";
72 public boolean isMetricsEnabled() {
77 public void metrics(String msg) {
81 public void metrics(String msg, Object arg) {
85 public void metrics(String msg, Object arg1, Object arg2) {
89 public void metrics(String msg, Object... arguments) {
93 public void metrics(String msg, Throwable throwable) {
97 public boolean isAuditEnabled() {
102 public void audit(String msg) {
106 public void audit(String msg, Object arg) {
110 public void audit(String msg, Object arg1, Object arg2) {
114 public void audit(String msg, Object... arguments) {
118 public void audit(String msg, Throwable throwable) {
122 public boolean isDebugEnabled() {
127 public void debug(String msg) {
131 public void debug(String msg, Object arg) {
135 public void debug(String msg, Object arg1, Object arg2) {
139 public void debug(String msg, Object... arguments) {
143 public void debug(String msg, Throwable throwable) {
147 public boolean isInfoEnabled() {
152 public void info(String msg) {
156 public void info(String msg, Object arg) {
160 public void info(String msg, Object arg1, Object arg2) {
164 public void info(String msg, Object... arguments) {
168 public void info(String msg, Throwable throwable) {
172 public boolean isWarnEnabled() {
177 public void warn(String msg) {
181 public void warn(String msg, Object arg) {
185 public void warn(String msg, Object... arguments) {
189 public void warn(String msg, Object arg1, Object arg2) {
193 public void warn(String msg, Throwable throwable) {
197 public boolean isErrorEnabled() {
202 public void error(String msg) {
206 public void error(String msg, Object arg) {
210 public void error(String msg, Object arg1, Object arg2) {
214 public void error(String msg, Object... arguments) {
218 public void error(String msg, Throwable throwable) {
223 public Logger getLogger(String className) {
228 public Logger getLogger(Class<?> clazz) {