2 * Copyright (C) 2016 - 2022 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcoreeelogger.beans.local.logger;
19 import javax.ejb.Singleton;
20 import javax.ejb.Startup;
21 import javax.inject.Inject;
22 import org.apache.logging.log4j.Logger;
25 * A "centralized" logger bean
27 * @author Roland Häder<roland@mxchange.org>
30 @Singleton (name = "logger", description = "A centralized logger bean")
31 public class LoggerBean implements LoggerBeanLocal {
36 private static final long serialVersionUID = 186_978_639_741_260L;
43 private Logger logger;
48 public LoggerBean () {
52 public void logDebug (final String message) {
53 // Validate parameters
54 if (null == message) {
56 throw new NullPointerException("message is null"); //NOI18N
57 } else if (message.isEmpty()) {
59 throw new IllegalArgumentException("message is empty"); //NOI18N
63 this.getLogger().debug(message);
67 public void logDebug (final String message, final Throwable cause) {
68 // Validate parameters
69 if (null == message) {
71 throw new NullPointerException("message is null"); //NOI18N
72 } else if (message.isEmpty()) {
74 throw new IllegalArgumentException("message is empty"); //NOI18N
75 } else if (null == cause) {
77 throw new NullPointerException("cause is null"); //NOI18N
81 this.getLogger().debug(message, cause);
85 public void logError (final String message) {
86 // Validate parameters
87 if (null == message) {
89 throw new NullPointerException("message is null"); //NOI18N
90 } else if (message.isEmpty()) {
92 throw new IllegalArgumentException("message is empty"); //NOI18N
96 this.getLogger().error(message);
100 public void logError (final String message, final Throwable cause) {
101 // Validate parameters
102 if (null == message) {
104 throw new NullPointerException("message is null"); //NOI18N
105 } else if (message.isEmpty()) {
107 throw new IllegalArgumentException("message is empty"); //NOI18N
108 } else if (null == cause) {
110 throw new NullPointerException("cause is null"); //NOI18N
113 // Deligate to logger
114 this.getLogger().error(message, cause);
118 public void logException (final Throwable throwable) {
119 // Validate parameter
120 if (null == throwable) {
122 throw new NullPointerException("throwable is null"); //NOI18N
125 // Deligate to logger
126 this.getLogger().catching(throwable);
130 public void logFatal (final String message, final Throwable cause) {
131 // Validate parameters
132 if (null == message) {
134 throw new NullPointerException("message is null"); //NOI18N
135 } else if (message.isEmpty()) {
137 throw new IllegalArgumentException("message is empty"); //NOI18N
138 } else if (null == cause) {
140 throw new NullPointerException("cause is null"); //NOI18N
143 // Deligate to logger
144 this.getLogger().fatal(message, cause);
148 public void logFatal (final String message) {
149 // Validate parameters
150 if (null == message) {
152 throw new NullPointerException("message is null"); //NOI18N
153 } else if (message.isEmpty()) {
155 throw new IllegalArgumentException("message is empty"); //NOI18N
158 // Deligate to logger
159 this.getLogger().fatal(message);
163 public void logInfo (final String message) {
164 // Validate parameters
165 if (null == message) {
167 throw new NullPointerException("message is null"); //NOI18N
168 } else if (message.isEmpty()) {
170 throw new IllegalArgumentException("message is empty"); //NOI18N
173 // Deligate to logger
174 this.getLogger().info(message);
178 public void logInfo (final String message, final Throwable cause) {
179 // Validate parameters
180 if (null == message) {
182 throw new NullPointerException("message is null"); //NOI18N
183 } else if (message.isEmpty()) {
185 throw new IllegalArgumentException("message is empty"); //NOI18N
186 } else if (null == cause) {
188 throw new NullPointerException("cause is null"); //NOI18N
191 // Deligate to logger
192 this.getLogger().info(message, cause);
196 public void logTrace (final String message) {
197 // Validate parameters
198 if (null == message) {
200 throw new NullPointerException("message is null"); //NOI18N
201 } else if (message.isEmpty()) {
203 throw new IllegalArgumentException("message is empty"); //NOI18N
206 // Deligate to logger
207 this.getLogger().trace(message);
211 public void logTrace (final String message, final Throwable cause) {
212 // Validate parameters
213 if (null == message) {
215 throw new NullPointerException("message is null"); //NOI18N
216 } else if (message.isEmpty()) {
218 throw new IllegalArgumentException("message is empty"); //NOI18N
219 } else if (null == cause) {
221 throw new NullPointerException("cause is null"); //NOI18N
224 // Deligate to logger
225 this.getLogger().trace(message, cause);
229 public void logWarning (final String message) {
230 // Validate parameters
231 if (null == message) {
233 throw new NullPointerException("message is null"); //NOI18N
234 } else if (message.isEmpty()) {
236 throw new IllegalArgumentException("message is empty"); //NOI18N
239 // Deligate to logger
240 this.getLogger().warn(message);
244 public void logWarning (final String message, final Throwable cause) {
245 // Validate parameters
246 if (null == message) {
248 throw new NullPointerException("message is null"); //NOI18N
249 } else if (message.isEmpty()) {
251 throw new IllegalArgumentException("message is empty"); //NOI18N
252 } else if (null == cause) {
254 throw new NullPointerException("cause is null"); //NOI18N
257 // Deligate to logger
258 this.getLogger().warn(message, cause);
266 private Logger getLogger () {