1 | /** |
2 | * BSD-style license; for more info see http://xradar.sourceforge.net/license.html |
3 | */ |
4 | package org.sourceforge.xradar.logging; |
5 | |
6 | import java.io.StringWriter; |
7 | import java.util.logging.Level; |
8 | import java.util.logging.Logger; |
9 | |
10 | /** |
11 | * A set of commonly used method to log |
12 | * @author rpelisse |
13 | * |
14 | */ |
15 | public final class LogUtils |
16 | { |
17 | // Util classe should not be constructed |
18 | private LogUtils(){} |
19 | |
20 | /** |
21 | * Set the $log param according to the current log level |
22 | * @param the logger |
23 | */ |
24 | public static boolean isLogEnabled(Logger logger) |
25 | { |
26 | // Retrieving current log level |
27 | Level logLevel = logger.getLevel(); |
28 | logger.setLevel(Level.FINEST); |
29 | // If it below WARNING, setting log level to true |
30 | if ( logLevel == null || ( |
31 | logLevel != null && |
32 | logLevel == Level.FINE || |
33 | logLevel == Level.FINER || |
34 | logLevel == Level.FINEST ) ) |
35 | { |
36 | return true; |
37 | } |
38 | else |
39 | return false; |
40 | } |
41 | |
42 | /** |
43 | * Commodity method to print to screen the result |
44 | * of mergings... |
45 | * @param logger,the logger |
46 | * @param buffer,the buffer |
47 | * @param mssg,the mssg |
48 | */ |
49 | public static void logBuffer(Logger logger,StringWriter buffer, String mssg) |
50 | { |
51 | logger.log(Level.FINEST,mssg); |
52 | logger.log(Level.FINEST,"********************************************************************************"); |
53 | if ( buffer != null && buffer.getBuffer() != null ) |
54 | logger.log(Level.FINEST,buffer.getBuffer().toString()); |
55 | logger.log(Level.FINEST,"********************************************************************************"); |
56 | } |
57 | |
58 | } |