01: // $Id$
02: /*
03: * Copyright (c) xsocket.org, 2006. 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 org.xsocket.mail;
23:
24: import java.text.MessageFormat;
25: import java.util.Date;
26: import java.util.logging.Formatter;
27: import java.util.logging.LogRecord;
28:
29: public class LogFormatter extends Formatter {
30:
31: private Date dat = new Date();
32: private MessageFormat formatter = new MessageFormat("{0,time}");
33:
34: private Object args[] = new Object[1];
35:
36: @Override
37: public String format(LogRecord record) {
38: StringBuffer sb = new StringBuffer();
39: // Minimize memory allocations here.
40: dat.setTime(record.getMillis());
41: args[0] = dat;
42: StringBuffer text = new StringBuffer();
43:
44: formatter.format(args, text, null);
45: sb.append(text);
46:
47: sb.append(" ");
48: sb.append(record.getThreadID());
49:
50: sb.append(" ");
51: sb.append(record.getLevel());
52:
53: sb.append(" [");
54: String clazzname = record.getSourceClassName();
55: int i = clazzname.lastIndexOf(".");
56: clazzname = clazzname.substring(i + 1, clazzname.length());
57: sb.append(clazzname);
58:
59: sb.append("#");
60: sb.append(record.getSourceMethodName());
61:
62: sb.append("] ");
63: sb.append(record.getMessage() + "\n");
64:
65: return sb.toString();
66: }
67:
68: }
|