KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > logging > VerifierFormatter


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 package com.sun.enterprise.logging;
24
25 import java.util.logging.SimpleFormatter JavaDoc;
26 import java.util.logging.LogRecord JavaDoc;
27 import java.io.StringWriter JavaDoc;
28 import java.io.PrintWriter JavaDoc;
29
30 /**
31  * The formatter class to suppress printing Date and Class information
32  * in the logged messages. It overrides the format(...) api of SimpleFormatter
33  * to provide the implementation.
34  *
35  * @author Vikas Awasthi
36  */

37 public class VerifierFormatter extends SimpleFormatter JavaDoc {
38
39     private String JavaDoc lineSeparator = (String JavaDoc) java.security.AccessController.doPrivileged(
40             new sun.security.action.GetPropertyAction("line.separator"));
41
42     public synchronized String JavaDoc format(LogRecord JavaDoc record) {
43         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
44         StringBuilder JavaDoc text = new StringBuilder JavaDoc();
45         sb.append(text);
46         sb.append(" ");
47         String JavaDoc message = formatMessage(record);
48         sb.append(record.getLevel().getLocalizedName());
49         sb.append(": ");
50         sb.append(message);
51         sb.append(lineSeparator);
52         if (record.getThrown() != null) {
53             try {
54                 StringWriter JavaDoc sw = new StringWriter JavaDoc();
55                 PrintWriter JavaDoc pw = new PrintWriter JavaDoc(sw);
56                 record.getThrown().printStackTrace(pw);
57                 pw.close();
58                 sb.append(sw.toString());
59             } catch (Exception JavaDoc ex) {
60             }
61         }
62         return sb.toString();
63     }
64 }
65
Popular Tags