| ClientLogInit.java |
1 package ch.ige.edossier.util;
2
3 import java.io.File;
4
5 /**
6 * B32.03 - eDossier-Interceptions - Diplomarbeit an der Software-Schule Schweiz<br>
7 * Hilfsklasse zur Initialisierung des Logging (Log4j)
8 * <p>
9 * Copyright (c) 2004, Eidgenössisches Institut für Geistiges Eigentum
10 * @author Anita Rueegsegger, Marc Bouquet
11 * @version $Id: ClientLogInit.java,v 1.3 2004/10/22 01:58:26 bouquet Exp $
12 */
13 public class ClientLogInit
14 {
15 /** the global default logging configuration file */
16 final public static String DEFAULT_CONFIG = "/ch/ige/edossier/util/default_config.xml";
17
18 /** Default Verzeichnis für die Logging-Daten */
19 final public static String DEFAULT_DIRECTORY = "c:/data/log/";
20
21 /**
22 * initializes logging with the global default configuration file.
23 * @see ClientLogInitalizer#initalizeLogging(String)
24 */
25 public static void initLogging()
26 {
27 ClientLogInit.checkLogDirectory( DEFAULT_DIRECTORY );
28 ClientLogInit.initLogging( DEFAULT_CONFIG );
29 }
30
31 /**
32 * Überprüft ob das Verzeichnis für die Logging-Daten vorhanden ist, wenn nicht wird es erstellt.
33 * @param path String path
34 * @throws Exception Unerwarteter Fehler
35 */
36 private static void checkLogDirectory( String path )
37 {
38 try
39 {
40 File file = new File( path );
41 if( !file.isDirectory() )
42 {
43 file.mkdirs();
44 }
45 }
46 catch( Exception ex )
47 {
48 ClientLogInit.logMessage( "Verzeichnis (c:/data/log) konnte nicht erstellt werden." );
49 }
50 }
51
52 /**
53 * Log4J configures itself with the config file provided with the 'log4j.configuration' property.
54 * check if the file which is specified with that property is really available.
55 * otherwise a default config file is used.
56 *
57 * the 'log4j.configuration' property can be set in the JNLP launch file
58 * or with a -Dlog4j.configuration=file:///c:/Programme/Ige/Log/config/jipps_config.xml parameter to the JVM.
59 * NOTE: URL values like 'file://c:/xyz' are not supported by the java URL handler.
60 *
61 * @param defaultXMLConfigResource the XML config file in the classpath.
62 */
63 public static void initLogging( String defaultXMLConfigResource )
64 {
65 String message;
66 try
67 {
68 //try to configure with the default config provided through the classloader
69 final java.net.URL configFileURL = ( ClientLogInit.class ).getResource( defaultXMLConfigResource );
70 org.apache.log4j.xml.DOMConfigurator.configure( configFileURL );
71 message = "log4j default logging gestartet.";
72 }
73 catch( Exception ex )
74 {
75 //if all fails we use the BasicConfigurator
76 org.apache.log4j.BasicConfigurator.configure();
77 message = "log4j basic logging gestartet.";
78 }
79 ClientLogInit.logMessage( message );
80 }
81
82 private static void logMessage( String message )
83 {
84 org.apache.log4j.Logger.getLogger( ClientLogInit.class ).debug( message );
85 }
86 }
87 | ClientLogInit.java |