1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.util;
19
20 import java.io.InputStream;
21 import java.io.IOException;
22
23 import java.security.AccessController;
24 import java.security.PrivilegedAction;
25
26 import java.util.logging.LogManager;
27
28 import org.apache.commons.logging.impl.Jdk14Logger;
29
30 /***
31 * JDO-specific subclass of the apache commons logging Log
32 * implementation that wraps the standard JDK 1.4 logging.
33 * This class configures the JDK LogManager using a properties file
34 * called logging.properties found via the CLASSPATH.
35 *
36 * @author Michael Bouschen
37 * @since 1.1
38 * @version 1.1
39 */
40 public class JDOJdk14Logger
41 extends Jdk14Logger
42 {
43 /*** Logging properties file name. */
44 public static final String PROPERIES_FILE = "logging.properties";
45
46 /*** Indicates whether JDK 1.4 logging has been configured by this class. */
47 private static boolean configured = false;
48
49 /*** I18N support. */
50 private final static I18NHelper msg =
51 I18NHelper.getInstance("org.apache.jdo.util.Bundle");
52
53 /***
54 * Constructor checking whether JDK 1.4 logging should be
55 * configuared after calling super constructor.
56 */
57 public JDOJdk14Logger(String name) {
58 super(name);
59 if (!configured) {
60 configured = true;
61 configureJDK14Logger();
62 }
63 }
64
65 /***
66 * Configures JDK 1.4 LogManager.
67 */
68 private void configureJDK14Logger() {
69 final LogManager logManager = LogManager.getLogManager();
70 final ClassLoader cl = getClass().getClassLoader();
71 AccessController.doPrivileged(new PrivilegedAction() {
72 public Object run () {
73 try {
74 InputStream config = cl.getResourceAsStream(PROPERIES_FILE);
75 logManager.readConfiguration(config);
76 return null;
77 }
78 catch (IOException ex) {
79 throw new RuntimeException(
80 msg.msg("EXC_LoggerSetupIOException",
81 PROPERIES_FILE) + ex);
82 }
83 catch (SecurityException ex) {
84 throw new RuntimeException(
85 msg.msg("EXC_LoggerSetupSecurityException",
86 PROPERIES_FILE) + ex);
87 }
88 }
89 });
90 }
91
92 }