KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > platform > server > ServerLog


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.platform.server;
23
24 import java.io.*;
25 import oracle.toplink.essentials.internal.helper.*;
26 import oracle.toplink.essentials.exceptions.*;
27 import oracle.toplink.essentials.logging.*;
28
29 /**
30  * <p>
31  * Basic logging class that provides framework for integration with the application
32  * server log. This class is used when messages need to be logged through an application
33  * server, e.g. OC4J.
34  *
35  * @see SessionLog
36  * @see AbstractSessionLog
37  * @see SessionLogEntry
38  * @see Session
39  * </p>
40  */

41 public class ServerLog extends AbstractSessionLog {
42
43     /**
44      * PUBLIC:
45      * <p>
46      * Create and return a new ServerLog.
47      * </p>
48      */

49     public ServerLog() {
50         super();
51         setLevel(INFO);
52     }
53
54     /**
55      * PUBLIC:
56      * <p>
57      * Log a SessionLogEntry
58      * </p><p>
59      *
60      * @param entry SessionLogEntry that holds all the information for a TopLink logging event
61      * </p>
62      */

63     public void log(SessionLogEntry entry) {
64         if (!shouldLog(entry.getLevel())) {
65             return;
66         }
67
68         String JavaDoc message = getSupplementDetailString(entry);
69
70         if (entry.hasException()) {
71             message += entry.getException();
72         } else {
73             message += formatMessage(entry);
74         }
75
76         basicLog(entry.getLevel(), message);
77     }
78
79     /**
80      * <p>
81      * Log message to a writer by default. It needs to be overridden by the subclasses.
82      * </p><p>
83      *
84      * @param level the log request level
85      * </p><p>
86      * @param message the formatted string message
87      * </p>
88      */

89     protected void basicLog(int level, String JavaDoc message) {
90         try {
91             printPrefixString(level);
92             getWriter().write(message);
93             getWriter().write(Helper.cr());
94             getWriter().flush();
95         } catch (IOException exception) {
96             throw ValidationException.logIOError(exception);
97         }
98     }
99 }
100
Popular Tags