KickJava   Java API By Example, From Geeks To Geeks.

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


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.logging.*;
28 import com.sun.enterprise.tools.upgrade.common.*;
29
30 /**
31  *
32  * author : Servesh Singh
33  *
34  */

35
36 public class LogService {
37
38     public static final String JavaDoc UPGRADE_LOGGER="com.sun.enterprise.tools.upgrade";
39     public static final String JavaDoc UPGRADE_CLI_LOGGER="com.sun.enterprise.tools.upgrade.cli";
40     public static final String JavaDoc UPGRADE_CERTCONVERSION_LOGGER="com.sun.enterprise.tools.upgrade.certconversion";
41     private static LogFormatter formatter;
42     private static FileHandler loghandler;
43
44     public static void initialize(String JavaDoc fileName) throws IOException{
45     LogManager.getLogManager().reset();
46     formatter = new LogFormatter();
47     boolean append = true;
48     int limit = 1000000;
49     loghandler = new FileHandler(fileName,limit,1,append);
50     loghandler.setLevel( Level.ALL );
51     loghandler.setFormatter(formatter);
52     }
53
54     public static Logger getLogger(String JavaDoc name) {
55     Logger logger = Logger.getLogger(name);
56         // TODO: Read a property from the file or System property and set this level.
57
// This will be useful for better debugging.
58
//logger.setLevel( Level.ALL );
59
Handler[] h = logger.getHandlers();
60     for (int i = 0; i < h.length; i++) {
61         logger.removeHandler(h[i]);
62     }
63     logger.addHandler(loghandler);
64     return logger;
65     }
66
67     public static void addLogMessageListener(LogMessageListener listener){
68     formatter.addLogMessageListener(listener);
69     }
70
71     public static void removeLogMessageListener(LogMessageListener listener){
72     formatter.removeLogMessageListener(listener);
73     }
74
75 }
76
77
Popular Tags