|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ServletPropertyConfigurator.java | - | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* Joey and its relative products are published under the terms
|
|
3 |
* of the Apache Software License.
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Created on 2003/12/27
|
|
7 |
*/
|
|
8 |
package org.asyrinx.brownie.log.log4j.servlet;
|
|
9 |
|
|
10 |
import java.util.Properties;
|
|
11 |
|
|
12 |
import javax.servlet.ServletContext;
|
|
13 |
|
|
14 |
import org.apache.log4j.Appender;
|
|
15 |
import org.apache.log4j.LogManager;
|
|
16 |
import org.apache.log4j.helpers.FileWatchdog;
|
|
17 |
import org.asyrinx.brownie.log.log4j.PropertyConfigurator;
|
|
18 |
import org.asyrinx.brownie.servlet.FileNameResolver;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* @author akima
|
|
22 |
*/
|
|
23 |
public class ServletPropertyConfigurator extends PropertyConfigurator { |
|
24 |
|
|
25 |
/**
|
|
26 |
*
|
|
27 |
*/
|
|
28 | 0 |
public ServletPropertyConfigurator(ServletContext servletContext) {
|
29 | 0 |
super();
|
30 | 0 |
this.resolver = new FileNameResolver(servletContext); |
31 |
} |
|
32 |
|
|
33 |
protected final FileNameResolver resolver;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* @see org.asyrinx.log.log4j.PropertyConfigurator#parseAppender(java.util.Properties,
|
|
37 |
* java.lang.String)
|
|
38 |
*/
|
|
39 | 0 |
protected Appender parseAppender(Properties props, String appenderName) {
|
40 | 0 |
final String fileKey = PropertyConfigurator.APPENDER_PREFIX |
41 |
+ appenderName + ".file";
|
|
42 | 0 |
final String origPath = props.getProperty(fileKey); |
43 | 0 |
props.setProperty(fileKey, resolver.toRealPath(origPath)); |
44 | 0 |
return super.parseAppender(props, appenderName); |
45 |
} |
|
46 |
|
|
47 |
/**
|
|
48 |
*/
|
|
49 | 0 |
static public void configure(String configFilename, |
50 |
ServletContext servletContext) { |
|
51 | 0 |
servletContext.log(ServletPropertyConfigurator.class.getName()
|
52 |
+ "#ServletPropertyConfigurator.configure(\"" + configFilename
|
|
53 |
+ "\")");
|
|
54 | 0 |
new ServletPropertyConfigurator(servletContext).doConfigure(
|
55 |
configFilename, LogManager.getLoggerRepository()); |
|
56 |
} |
|
57 |
|
|
58 |
/**
|
|
59 |
* Like {@link #configureAndWatch(String, long)}except that the default
|
|
60 |
* delay as defined by {@link FileWatchdog#DEFAULT_DELAY}is used.
|
|
61 |
*
|
|
62 |
* @param configFilename
|
|
63 |
* A file in key=value format.
|
|
64 |
*
|
|
65 |
*/
|
|
66 | 0 |
static public void configureAndWatch(String configFilename, |
67 |
ServletContext servletContext) { |
|
68 | 0 |
configureAndWatch(configFilename, FileWatchdog.DEFAULT_DELAY, |
69 |
servletContext); |
|
70 |
} |
|
71 |
|
|
72 |
/**
|
|
73 |
* Read the configuration file <code>configFilename</code> if it exists.
|
|
74 |
* Moreover, a thread will be created that will periodically check if
|
|
75 |
* <code>configFilename</code> has been created or modified. The period is
|
|
76 |
* determined by the <code>delay</code> argument. If a change or file
|
|
77 |
* creation is detected, then <code>configFilename</code> is read to
|
|
78 |
* configure log4j.
|
|
79 |
*
|
|
80 |
* @param configFilename
|
|
81 |
* A file in key=value format.
|
|
82 |
* @param delay
|
|
83 |
* The delay in milliseconds to wait between each check.
|
|
84 |
*/
|
|
85 | 0 |
static public void configureAndWatch(String configFilename, long delay, |
86 |
ServletContext servletContext) { |
|
87 | 0 |
servletContext.log(ServletPropertyConfigurator.class.getName()
|
88 |
+ "#ServletPropertyConfigurator.configureAndWatch(\""
|
|
89 |
+ configFilename + "\")");
|
|
90 | 0 |
ServletPropertyWatchdog pdog = new ServletPropertyWatchdog(
|
91 |
configFilename, servletContext); |
|
92 | 0 |
pdog.setDelay(delay); |
93 | 0 |
pdog.start(); |
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
class ServletPropertyWatchdog extends FileWatchdog { |
|
98 |
|
|
99 | 0 |
ServletPropertyWatchdog(String filename, ServletContext servletContext) { |
100 | 0 |
super(filename);
|
101 | 0 |
this.servletContext = servletContext;
|
102 |
} |
|
103 |
|
|
104 |
final ServletContext servletContext; |
|
105 |
|
|
106 |
/**
|
|
107 |
* Call {@link PropertyConfigurator#configure(String)}with the
|
|
108 |
* <code>filename</code> to reconfigure log4j.
|
|
109 |
*/
|
|
110 | 0 |
public void doOnChange() { |
111 | 0 |
new ServletPropertyConfigurator(servletContext).doConfigure(filename,
|
112 |
LogManager.getLoggerRepository()); |
|
113 |
} |
|
114 |
} |
|