KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > logging > SystemLogHandler


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.server.logging;
24
25 import java.util.logging.Handler JavaDoc;
26 import java.util.logging.LogRecord JavaDoc;
27
28 import com.sun.enterprise.util.SystemPropertyConstants;
29
30
31 public class SystemLogHandler extends Handler JavaDoc {
32     public native void logMessage(String JavaDoc fileName, String JavaDoc level,
33         String JavaDoc message);
34
35     private static final String JavaDoc SYSLOG_FILE_PREFIX = "SJSAS81";
36
37     // We set the prefix first and then build the complete file
38
// name in the constructor.
39
private String JavaDoc syslogFileName = SYSLOG_FILE_PREFIX;
40
41     public SystemLogHandler( ) {
42         try {
43             System.loadLibrary( "utilforsyslog" );
44             // We will build the syslogFileName which will be in the format
45
// SJSAS81_<ClusterId>_<ServerId>.log
46
// This will let users to configure Syslog to send out all
47
// AppServer Logs running on different instances to log to
48
// one central server, similarly can do the same at the
49
// cluster level as well.
50
String JavaDoc serverName = System.getProperty(
51                 SystemPropertyConstants.SERVER_NAME );
52             String JavaDoc clusterId = System.getProperty(
53                 SystemPropertyConstants.CLUSTER_NAME );
54             if( clusterId != null ) {
55                 syslogFileName = syslogFileName + "_" + clusterId;
56             }
57             if( serverName != null ) {
58                 syslogFileName = syslogFileName + "_" + serverName;
59             }
60             syslogFileName = syslogFileName + ".log";
61         } catch( Exception JavaDoc e ) {
62             System.err.println( "Exception in loading Syslog Library..." + e );
63             e.printStackTrace( );
64         }
65     }
66
67     public synchronized void publish( LogRecord JavaDoc record ) {
68         logMessage( syslogFileName, record.getLevel().toString(),
69             getFormatter().format( record ) );
70     }
71
72     public void close( ) { }
73
74     public void flush( ) { }
75 }
76
77  
78     
79
Popular Tags