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