]> git.mxchange.org Git - jcore-logger-ejb.git/blob - src/java/org/mxchange/jcoreeelogger/beans/local/logger/LoggerBean.java
36d208a56b9d0ff28f712c5513c667d7993ae893
[jcore-logger-ejb.git] / src / java / org / mxchange / jcoreeelogger / beans / local / logger / LoggerBean.java
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcoreeelogger.beans.local.logger;
18
19 import javax.ejb.Singleton;
20 import javax.ejb.Startup;
21 import javax.inject.Inject;
22 import org.apache.logging.log4j.Logger;
23
24 /**
25  * A "centralized" logger bean
26  * <p>
27  * @author Roland Häder<roland@mxchange.org>
28  */
29 @Startup
30 @Singleton (name = "logger", description = "A centralized logger bean")
31 public class LoggerBean implements LoggerBeanLocal {
32
33         /**
34          * Serial number
35          */
36         private static final long serialVersionUID = 186_978_639_741_260L;
37
38         /**
39          * Logger instance
40          */
41         @Inject
42         @Log
43         private Logger logger;
44
45         /**
46          * Default constructor
47          */
48         public LoggerBean () {
49         }
50
51         @Override
52         public void logDebug (final String message) {
53                 // Validate parameters
54                 if (null == message) {
55                         // Throw NPE
56                         throw new NullPointerException("message is null"); //NOI18N
57                 } else if (message.isEmpty()) {
58                         // Throw IAE
59                         throw new IllegalArgumentException("message is empty"); //NOI18N
60                 }
61
62                 // Deligate to logger
63                 this.getLogger().debug(message);
64         }
65
66         @Override
67         public void logDebug (final String message, final Throwable cause) {
68                 // Validate parameters
69                 if (null == message) {
70                         // Throw NPE
71                         throw new NullPointerException("message is null"); //NOI18N
72                 } else if (message.isEmpty()) {
73                         // Throw IAE
74                         throw new IllegalArgumentException("message is empty"); //NOI18N
75                 } else if (null == cause) {
76                         // Throw NPE again
77                         throw new NullPointerException("cause is null"); //NOI18N
78                 }
79
80                 // Deligate to logger
81                 this.getLogger().debug(message, cause);
82         }
83
84         @Override
85         public void logError (final String message) {
86                 // Validate parameters
87                 if (null == message) {
88                         // Throw NPE
89                         throw new NullPointerException("message is null"); //NOI18N
90                 } else if (message.isEmpty()) {
91                         // Throw IAE
92                         throw new IllegalArgumentException("message is empty"); //NOI18N
93                 }
94
95                 // Deligate to logger
96                 this.getLogger().error(message);
97         }
98
99         @Override
100         public void logError (final String message, final Throwable cause) {
101                 // Validate parameters
102                 if (null == message) {
103                         // Throw NPE
104                         throw new NullPointerException("message is null"); //NOI18N
105                 } else if (message.isEmpty()) {
106                         // Throw IAE
107                         throw new IllegalArgumentException("message is empty"); //NOI18N
108                 } else if (null == cause) {
109                         // Throw NPE again
110                         throw new NullPointerException("cause is null"); //NOI18N
111                 }
112
113                 // Deligate to logger
114                 this.getLogger().error(message, cause);
115         }
116
117         @Override
118         public void logException (final Throwable throwable) {
119                 // Validate parameter
120                 if (null == throwable) {
121                         // Throw NPE again
122                         throw new NullPointerException("throwable is null"); //NOI18N
123                 }
124
125                 // Deligate to logger
126                 this.getLogger().catching(throwable);
127         }
128
129         @Override
130         public void logFatal (final String message, final Throwable cause) {
131                 // Validate parameters
132                 if (null == message) {
133                         // Throw NPE
134                         throw new NullPointerException("message is null"); //NOI18N
135                 } else if (message.isEmpty()) {
136                         // Throw IAE
137                         throw new IllegalArgumentException("message is empty"); //NOI18N
138                 } else if (null == cause) {
139                         // Throw NPE again
140                         throw new NullPointerException("cause is null"); //NOI18N
141                 }
142
143                 // Deligate to logger
144                 this.getLogger().fatal(message, cause);
145         }
146
147         @Override
148         public void logFatal (final String message) {
149                 // Validate parameters
150                 if (null == message) {
151                         // Throw NPE
152                         throw new NullPointerException("message is null"); //NOI18N
153                 } else if (message.isEmpty()) {
154                         // Throw IAE
155                         throw new IllegalArgumentException("message is empty"); //NOI18N
156                 }
157
158                 // Deligate to logger
159                 this.getLogger().fatal(message);
160         }
161
162         @Override
163         public void logInfo (final String message) {
164                 // Validate parameters
165                 if (null == message) {
166                         // Throw NPE
167                         throw new NullPointerException("message is null"); //NOI18N
168                 } else if (message.isEmpty()) {
169                         // Throw IAE
170                         throw new IllegalArgumentException("message is empty"); //NOI18N
171                 }
172
173                 // Deligate to logger
174                 this.getLogger().info(message);
175         }
176
177         @Override
178         public void logInfo (final String message, final Throwable cause) {
179                 // Validate parameters
180                 if (null == message) {
181                         // Throw NPE
182                         throw new NullPointerException("message is null"); //NOI18N
183                 } else if (message.isEmpty()) {
184                         // Throw IAE
185                         throw new IllegalArgumentException("message is empty"); //NOI18N
186                 } else if (null == cause) {
187                         // Throw NPE again
188                         throw new NullPointerException("cause is null"); //NOI18N
189                 }
190
191                 // Deligate to logger
192                 this.getLogger().info(message, cause);
193         }
194
195         @Override
196         public void logTrace (final String message) {
197                 // Validate parameters
198                 if (null == message) {
199                         // Throw NPE
200                         throw new NullPointerException("message is null"); //NOI18N
201                 } else if (message.isEmpty()) {
202                         // Throw IAE
203                         throw new IllegalArgumentException("message is empty"); //NOI18N
204                 }
205
206                 // Deligate to logger
207                 this.getLogger().trace(message);
208         }
209
210         @Override
211         public void logTrace (final String message, final Throwable cause) {
212                 // Validate parameters
213                 if (null == message) {
214                         // Throw NPE
215                         throw new NullPointerException("message is null"); //NOI18N
216                 } else if (message.isEmpty()) {
217                         // Throw IAE
218                         throw new IllegalArgumentException("message is empty"); //NOI18N
219                 } else if (null == cause) {
220                         // Throw NPE again
221                         throw new NullPointerException("cause is null"); //NOI18N
222                 }
223
224                 // Deligate to logger
225                 this.getLogger().trace(message, cause);
226         }
227
228         @Override
229         public void logWarning (final String message) {
230                 // Validate parameters
231                 if (null == message) {
232                         // Throw NPE
233                         throw new NullPointerException("message is null"); //NOI18N
234                 } else if (message.isEmpty()) {
235                         // Throw IAE
236                         throw new IllegalArgumentException("message is empty"); //NOI18N
237                 }
238
239                 // Deligate to logger
240                 this.getLogger().warn(message);
241         }
242
243         @Override
244         public void logWarning (final String message, final Throwable cause) {
245                 // Validate parameters
246                 if (null == message) {
247                         // Throw NPE
248                         throw new NullPointerException("message is null"); //NOI18N
249                 } else if (message.isEmpty()) {
250                         // Throw IAE
251                         throw new IllegalArgumentException("message is empty"); //NOI18N
252                 } else if (null == cause) {
253                         // Throw NPE again
254                         throw new NullPointerException("cause is null"); //NOI18N
255                 }
256
257                 // Deligate to logger
258                 this.getLogger().warn(message, cause);
259         }
260
261         /**
262          * Getter for logger
263          * <p>
264          * @return Logger
265          */
266         private Logger getLogger () {
267                 return this.logger;
268         }
269
270 }