OSDN Git Service

ver 2.23 init
[hayashilib/hayashi.git] / src / hayashi / yuu / tools / logger / YuuLogFormatter.java
1 package hayashi.yuu.tools.logger;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5 import java.util.logging.Formatter;
6 import java.util.logging.Level;
7 import java.util.logging.LogRecord;
8
9 /**
10  * シンプルなサンプルログフォーマッタ
11  */
12 public class YuuLogFormatter extends Formatter {
13     private final SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
14
15     public String format(final LogRecord argLogRecord) {
16         final StringBuffer buf = new StringBuffer();
17
18         buf.append(sdFormat.format(new Date(argLogRecord.getMillis())) +" ");
19
20         if (argLogRecord.getLevel() == Level.FINEST) {
21             buf.append("[FINEST]");
22         }
23         else if (argLogRecord.getLevel() == Level.FINER) {
24             buf.append("[FINER]");
25         }
26         else if (argLogRecord.getLevel() == Level.FINE) {
27             buf.append("[FINE]");
28         }
29         else if (argLogRecord.getLevel() == Level.CONFIG) {
30             buf.append("[CONFIG]");
31         }
32         else if (argLogRecord.getLevel() == Level.INFO) {
33             buf.append("[INFO]");
34         }
35         else if (argLogRecord.getLevel() == Level.WARNING) {
36             buf.append("[WARN]");
37         }
38         else if (argLogRecord.getLevel() == Level.SEVERE) {
39             buf.append("[SEVERE]");
40         }
41         else {
42             buf.append(Integer.toString(argLogRecord.getLevel().intValue()) +" ");
43         }
44         buf.append(" "+ /* argLogRecord.getLoggerName() +" - "+ */ argLogRecord.getMessage() +"\n");
45         return buf.toString();
46     }
47 }