KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > logging > LogFormatter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.upgrade.logging;
25
26 import java.io.*;
27 import java.util.*;
28 import java.util.logging.*;
29 import java.text.*;
30 import com.sun.enterprise.tools.upgrade.common.*;
31 import com.sun.enterprise.server.logging.UniformLogFormatter;
32
33 /**
34  *
35  * author : Servesh Singh
36  *
37  */

38
39 public class LogFormatter extends UniformLogFormatter {
40
41     private static List listenerList = new ArrayList();
42
43  public String JavaDoc format(LogRecord rec) {
44  /*
45     StringBuffer buf = new StringBuffer(1000);
46     buf.append("[");
47     buf.append(rec.getLevel());
48     buf.append("|");
49     buf.append(getForamtedDate(rec.getMillis()));
50     buf.append("|");
51     buf.append(rec.getLoggerName( ));
52     buf.append("|");
53     buf.append("ThreadID="+rec.getThreadID( ));
54     buf.append("|");
55     buf.append(formatMessage(rec));
56     Throwable th = rec.getThrown();
57     if(th !=null) {
58         buf.append("|");
59         buf.append("\n");
60         buf.append(" message: "+th.getMessage());
61         StackTraceElement[] st = th.getStackTrace();
62         buf.append("\n");
63         for(int i =0;i<st.length;i++){
64             buf.append(" "+st[i]);
65             buf.append("\n");
66         }
67     }
68     buf.append("]");
69     buf.append('\n');
70     String msg = buf.toString();
71  */

72
73         notifyRegisteredListeners(rec.getMessage(),rec);
74     return super.format(rec);
75     }
76
77     private void notifyRegisteredListeners(String JavaDoc msg, LogRecord record){
78     int size = listenerList.size();
79     for(int i =0; i<size;i++) {
80         LogMessageListener listener = (LogMessageListener)listenerList.get(i);
81         LogMessageEvent e = new LogMessageEvent("UpgradeTool", msg);
82          e.setLogRecord(record);
83         listener.logMessageReceived(e);
84     }
85     }
86 /*
87     public String getHead(Handler h) {
88     return "\n";
89     }
90
91     public String getTail(Handler h) {
92     return "\n";
93     }
94 */

95     public static void addLogMessageListener(LogMessageListener listener){
96         listenerList.add(listener);
97     }
98
99     public static void removeLogMessageListener(LogMessageListener listener){
100     listenerList.remove(listener);
101     }
102 /*
103     public String getForamtedDate(long milisecond) {
104     SimpleDateFormat dateformat = new SimpleDateFormat("yyyy MMMMM dd hh:mm: ss aaa");
105     StringBuffer bf = new StringBuffer();
106     dateformat.format(new Date(milisecond),bf,new FieldPosition(0));
107     return bf.toString();
108     }
109  */

110  }
111
112
Popular Tags