@@ -142,7 +142,7 @@ public String format(LogRecord record) {
142
142
143
143
/**
144
144
* Prints a stack trace as nicely as {@code e.printStackTrace()}, but uses the logging system as output.
145
- *
145
+ *
146
146
* @param e A {@code Throwable} thats stack trace should be printed.
147
147
*/
148
148
public synchronized void printStackTrace (Throwable e ) {
@@ -153,7 +153,7 @@ public synchronized void printStackTrace(Throwable e) {
153
153
154
154
/**
155
155
* Appends the stack trace for the given {@link Throwable} to the given {@link StringBuilder}.
156
- *
156
+ *
157
157
* @param sb {@code StringBuilder} as output for the stack trace.
158
158
* @param e A {@code Throwable} which stack trace should be appended. If {@code null} given, nothing is appended.
159
159
*/
@@ -168,7 +168,7 @@ protected static void printStackTrace(StringBuilder sb, Throwable e) {
168
168
169
169
/**
170
170
* Just calls the parent constructor and adds the new instance to the LogManager.
171
- *
171
+ *
172
172
* @param name A name for the logger. This should be a dot-separated name and should normally be based on the
173
173
* package name or class name of the subsystem, such as java.net or javax.swing. It may be null for
174
174
* anonymous Loggers.
@@ -190,7 +190,7 @@ protected L2pLogger(String name, String resourceBundleName) throws IllegalArgume
190
190
191
191
/**
192
192
* Same as {@link #setLogDirectory(String)} for the global static instance.
193
- *
193
+ *
194
194
* @param directory A directory path given as String. {@code null} is equal to "" and the class loader directory.
195
195
* @throws IOException
196
196
*/
@@ -200,7 +200,7 @@ public static void setGlobalLogDirectory(String directory) throws IOException {
200
200
201
201
/**
202
202
* Sets the directory to store log files.
203
- *
203
+ *
204
204
* @param directory A directory path given as String. {@code null} is equal to "" and the class loader directory.
205
205
* @throws IOException
206
206
*/
@@ -218,7 +218,7 @@ public synchronized void setLogDirectory(String directory) throws IOException {
218
218
219
219
/**
220
220
* Same as {@link #setLogfilePrefix(String)} for global static instance.
221
- *
221
+ *
222
222
* @param prefix If {@code null} is given, file logging will be disabled.
223
223
* @throws IOException
224
224
*/
@@ -228,7 +228,7 @@ public static void setGlobalLogfilePrefix(String prefix) throws IOException {
228
228
229
229
/**
230
230
* Sets the prefix used to generate log files.
231
- *
231
+ *
232
232
* @param prefix If {@code null} is given, file logging will be disabled.
233
233
* @throws IOException
234
234
*/
@@ -243,7 +243,7 @@ public synchronized void setLogfilePrefix(String prefix) throws IOException {
243
243
244
244
/**
245
245
* This method must be called each time the log file target is changed.
246
- *
246
+ *
247
247
* @throws IOException
248
248
*/
249
249
private synchronized void updateLogfileHandler () throws IOException {
@@ -277,7 +277,7 @@ private synchronized void updateLogfileHandler() throws IOException {
277
277
278
278
/**
279
279
* This method ensures that the given directory is actually a directory and exists.
280
- *
280
+ *
281
281
* @param dir A path given as String for the desired directory
282
282
* @throws IOException return null;
283
283
*/
@@ -290,7 +290,7 @@ private static void createDir(String dir) throws IOException {
290
290
291
291
/**
292
292
* Same as {@link #setConsoleLevel(Level)} for the global static instance.
293
- *
293
+ *
294
294
* @param level The log level to set.
295
295
*/
296
296
public static void setGlobalConsoleLevel (Level level ) {
@@ -299,7 +299,7 @@ public static void setGlobalConsoleLevel(Level level) {
299
299
300
300
/**
301
301
* Sets the log level for the console output of this logger.
302
- *
302
+ *
303
303
* @param level The log level to set.
304
304
*/
305
305
public synchronized void setConsoleLevel (Level level ) {
@@ -309,7 +309,7 @@ public synchronized void setConsoleLevel(Level level) {
309
309
310
310
/**
311
311
* Same as {@link #setLogfileLevel(Level)} for global static instance.
312
- *
312
+ *
313
313
* @param level The log level to set.
314
314
*/
315
315
public static void setGlobalLogfileLevel (Level level ) {
@@ -318,7 +318,7 @@ public static void setGlobalLogfileLevel(Level level) {
318
318
319
319
/**
320
320
* Sets the log level for the log files used in this logger.
321
- *
321
+ *
322
322
* @param level The log level to set.
323
323
*/
324
324
public synchronized void setLogfileLevel (Level level ) {
@@ -361,7 +361,7 @@ public void log(LogRecord record) {
361
361
362
362
/**
363
363
* Writes a log message. The given event can be used to differentiate between different log messages.
364
- *
364
+ *
365
365
* @param event used to differentiate between different log messages
366
366
* @param message
367
367
*/
@@ -371,7 +371,7 @@ public static void logEvent(Event event, String message) {
371
371
372
372
/**
373
373
* Writes a log message. The given event can be used to differentiate between different log messages.
374
- *
374
+ *
375
375
* @param event used to differentiate between different log messages
376
376
* @param actingUser can be set to null if unknown / not desired
377
377
* @param message
@@ -389,10 +389,10 @@ public static void logEvent(Event event, Agent actingUser, String message) {
389
389
390
390
/**
391
391
* Logs a message to the l2p system using the observers.
392
- *
392
+ *
393
393
* Since this method will/should only be used in an L2pThread, the message will come from a service or a helper, so
394
394
* a SERVICE_MESSAGE is assumed. Then this message will not be monitored by the monitoring observer.
395
- *
395
+ *
396
396
* @param from the calling class
397
397
* @param event used to differentiate between different log messages
398
398
* @param message
@@ -405,11 +405,11 @@ public static void logEvent(Object from, Event event, String message) {
405
405
* Writes a log message. The given event can be used to differentiate between different log messages. The
406
406
* serviceAgent and actingUser can be set to {@code null} if not known. Then this message will not be monitored by
407
407
* the monitoring observer.
408
- *
408
+ *
409
409
* This method replaces: {@link Context#logMessage(Object, int, String, Agent, Agent)},
410
410
* {@link Context#logMessage(Object, String)}, {@link Context#logError(Object, int, String, Agent, Agent)},
411
411
* {@link Context#logError(Object, String)}, {@link Service#logError(String message)}
412
- *
412
+ *
413
413
* @param from the calling class
414
414
* @param event used to differentiate between different log messages
415
415
* @param message
@@ -430,7 +430,7 @@ public static void logEvent(Object from, Event event, String message, Agent serv
430
430
* Writes a log message. The given event can be used to differentiate between different log messages. The
431
431
* serviceAgent and actingUser can be set to {@code null} if not known. Then this message will not be monitored by
432
432
* the monitoring observer.
433
- *
433
+ *
434
434
* @param node
435
435
* @param from the calling class
436
436
* @param event used to differentiate between different log messages
@@ -466,20 +466,21 @@ public void log(Long timestamp, Event event, String sourceNode, Long sourceAgent
466
466
467
467
/**
468
468
* Simple method for one log line entry. Null will be printed as "-". All values will be followed by a tab char.
469
- *
469
+ *
470
470
* @param o
471
471
* @return a string
472
472
*/
473
473
private static String appendPart (Object o ) {
474
- if (o == null )
474
+ if (o == null ) {
475
475
return "-\t " ;
476
- else
476
+ } else {
477
477
return "" + o + "\t " ;
478
+ }
478
479
}
479
480
480
481
/**
481
482
* This method returns the default {@link Formatter} currently used to format log output for console.
482
- *
483
+ *
483
484
* @return Returns the console formatter.
484
485
*/
485
486
public static Formatter getGlobalConsoleFormatter () {
@@ -488,25 +489,38 @@ public static Formatter getGlobalConsoleFormatter() {
488
489
489
490
/**
490
491
* This method returns the default {@link Formatter} currently used to format log output for log files.
491
- *
492
+ *
492
493
* @return Returns the log file formatter.
493
494
*/
494
495
public static Formatter getGlobalLogfileFormatter () {
495
496
return GLOBAL_INSTANCE .logfileFormatter ;
496
497
}
497
498
498
499
/**
499
- * This method is the recommended way to retrieve a L2pLogger instance.
500
- *
500
+ * This method is used to retrieve a L2pLogger instance.
501
+ *
502
+ * @param cls Should be the class this instance is used with.
503
+ * @return Returns a L2pLogger instance for the given class.
504
+ * @throws ClassCastException If someone overloaded the loggers instance by adding some other logger implementation
505
+ * with the same name. In this case you may use Java native method by calling
506
+ * {@link Logger#getLogger(String)}.
507
+ */
508
+ public static L2pLogger getInstance (Class <?> cls ) throws ClassCastException {
509
+ return getInstance (cls .getCanonicalName ());
510
+ }
511
+
512
+ /**
513
+ * This method is used to retrieve a L2pLogger instance.
514
+ *
501
515
* @param name A name for the new logger instance. Should be the name of your current class by default. Like
502
- * L2pLogger.class.getName ()
516
+ * L2pLogger.class.getCanonicalName ()
503
517
* @return Returns a L2pLogger instance for the given name.
504
518
* @throws ClassCastException If someone overloaded the loggers instance by adding some other logger implementation
505
519
* with the same name. In this case you may use Java native method by calling
506
520
* {@link Logger#getLogger(String)}.
507
521
*/
508
522
public static L2pLogger getInstance (String name ) throws ClassCastException {
509
- if (name == null || name .isEmpty () || "i5.las2peer" .equals (name ) || ! name . startsWith ( "i5.las2peer" ) ) {
523
+ if (name == null || name .isEmpty () || "i5.las2peer" .equals (name )) {
510
524
throw new IllegalArgumentException ("Invalid logger name '" + name + "' given!" );
511
525
}
512
526
L2pLogger result = null ;
0 commit comments