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