Mercurial > dive4elements > http-client
comparison src/main/java/org/dive4elements/artifacts/httpclient/ConsoleClient.java @ 124:7261c948425c 3.2.x
Rely on log4j's default initialization procedure
This should make upgrading to Log4j 2.x easier.
In passing, use latest Log4j 1.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 25 Feb 2022 15:15:04 +0100 |
parents | 133281653904 |
children | e602a29f1dcc |
comparison
equal
deleted
inserted
replaced
123:ddbb7256246f | 124:7261c948425c |
---|---|
11 import java.io.IOException; | 11 import java.io.IOException; |
12 import java.io.File; | 12 import java.io.File; |
13 import java.io.FileOutputStream; | 13 import java.io.FileOutputStream; |
14 import java.io.OutputStream; | 14 import java.io.OutputStream; |
15 | 15 |
16 import java.net.MalformedURLException; | |
17 | |
18 import java.util.Arrays; | 16 import java.util.Arrays; |
19 import java.util.ArrayList; | 17 import java.util.ArrayList; |
20 import java.util.HashMap; | 18 import java.util.HashMap; |
21 import java.util.List; | 19 import java.util.List; |
22 import java.util.Map; | 20 import java.util.Map; |
26 import org.w3c.dom.Document; | 24 import org.w3c.dom.Document; |
27 import org.w3c.dom.Node; | 25 import org.w3c.dom.Node; |
28 import org.w3c.dom.NodeList; | 26 import org.w3c.dom.NodeList; |
29 | 27 |
30 import org.apache.log4j.Logger; | 28 import org.apache.log4j.Logger; |
31 import org.apache.log4j.PropertyConfigurator; | |
32 | 29 |
33 import org.dive4elements.artifacts.httpclient.http.HttpClient; | 30 import org.dive4elements.artifacts.httpclient.http.HttpClient; |
34 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; | 31 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; |
35 import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; | 32 import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; |
36 | 33 |
46 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 43 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
47 */ | 44 */ |
48 public class ConsoleClient | 45 public class ConsoleClient |
49 { | 46 { |
50 /** | 47 /** |
51 * The logging is done via Log4j. To configure the logging | |
52 * a file 'log4j.properties' is search in the configuration directory. | |
53 */ | |
54 public static final String LOG4J_PROPERTIES = "log4j.properties"; | |
55 | |
56 | |
57 /** | |
58 * The path of the configuration directory. | 48 * The path of the configuration directory. |
59 */ | 49 */ |
60 public static final String CONFIG_PATH = System.getProperty("config.dir", | 50 public static final String CONFIG_PATH = System.getProperty("config.dir", |
61 "conf"); | 51 "conf"); |
62 | 52 |
67 public static final String XPATH_DYNAMIC = "/art:result/art:ui/art:dynamic"; | 57 public static final String XPATH_DYNAMIC = "/art:result/art:ui/art:dynamic"; |
68 | 58 |
69 /** | 59 /** |
70 * The logger used in this class. | 60 * The logger used in this class. |
71 */ | 61 */ |
72 private static Logger logger; | 62 private static Logger logger = Logger.getLogger(ConsoleClient.class); |
73 | |
74 | |
75 static { | |
76 configureLogging(); | |
77 | |
78 logger = Logger.getLogger(ConsoleClient.class); | |
79 } | |
80 | |
81 | |
82 /** | |
83 * Trys to load the Log4j configuration from ${config.dir}/log4j.properties. | |
84 */ | |
85 public static final void configureLogging() { | |
86 File configDir = new File(CONFIG_PATH); | |
87 File propFile = new File(configDir, LOG4J_PROPERTIES); | |
88 | |
89 if (propFile.isFile() && propFile.canRead()) { | |
90 try { | |
91 PropertyConfigurator.configure(propFile.toURI().toURL()); | |
92 } | |
93 catch (MalformedURLException mue) { | |
94 mue.printStackTrace(System.err); | |
95 } | |
96 } | |
97 } | |
98 | 63 |
99 | 64 |
100 public static final Configuration readConfiguration() { | 65 public static final Configuration readConfiguration() { |
101 File configDir = new File(CONFIG_PATH); | 66 File configDir = new File(CONFIG_PATH); |
102 File configFile = new File(configDir, CONFIG); | 67 File configFile = new File(configDir, CONFIG); |