01: // $Id: LogFormatter.java 1134 2007-04-05 17:44:43Z grro $
02: /*
03: * Copyright (c) xsocket.org, 2006 - 2007. All rights reserved.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
20: * The latest copy of this software may be found on http://www.xsocket.org/
21: */
22: package distributedcache;
23:
24: import java.text.SimpleDateFormat;
25: import java.util.logging.Formatter;
26: import java.util.logging.LogRecord;
27:
28: /**
29: *
30: * @author grro
31: */
32: public class LogFormatter extends Formatter {
33:
34: public static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat(
35: "hh::mm::ss,S");
36:
37: @Override
38: public String format(LogRecord record) {
39: StringBuffer sb = new StringBuffer();
40:
41: sb.append(DATEFORMAT.format(record.getMillis()));
42:
43: sb.append(" ");
44: sb.append(record.getThreadID());
45:
46: sb.append(" ");
47: sb.append(record.getLevel());
48:
49: sb.append(" [");
50: String clazzname = record.getSourceClassName();
51: int i = clazzname.lastIndexOf(".");
52: clazzname = clazzname.substring(i + 1, clazzname.length());
53: sb.append(clazzname);
54:
55: sb.append("#");
56: sb.append(record.getSourceMethodName());
57:
58: sb.append("] ");
59: sb.append(record.getMessage() + "\n");
60:
61: return sb.toString();
62: }
63:
64: }
|