Roberto Sánchez
2014-02-24 fcf951f23acc8160a4433892cd15680d247fe126
#593 feature - Proper configuration for log4j2 and slf4j
4 files modified
changed files
pom.xml patch | view | blame | history
src/main/java/net/curisit/securis/License.java patch | view | blame | history
src/main/java/net/curisit/securis/SignatureHelper.java patch | view | blame | history
src/main/java/net/curisit/securis/utils/Params.java patch | view | blame | history
pom.xml
....@@ -17,11 +17,6 @@
1717 </build>
1818 <dependencies>
1919 <dependency>
20
- <groupId>org.slf4j</groupId>
21
- <artifactId>log4j-over-slf4j</artifactId>
22
- <version>1.7.6</version>
23
- </dependency>
24
- <dependency>
2520 <groupId>org.apache.commons</groupId>
2621 <artifactId>commons-lang3</artifactId>
2722 <version>3.2.1</version>
....@@ -48,7 +43,12 @@
4843 </dependency>
4944 <dependency>
5045 <groupId>org.apache.logging.log4j</groupId>
51
- <artifactId>log4j-api</artifactId>
46
+ <artifactId>log4j-slf4j-impl</artifactId>
47
+ <version>2.0-rc1</version>
48
+ </dependency>
49
+ <dependency>
50
+ <groupId>org.apache.logging.log4j</groupId>
51
+ <artifactId>log4j-core</artifactId>
5252 <version>2.0-rc1</version>
5353 </dependency>
5454 </dependencies>
src/main/java/net/curisit/securis/License.java
....@@ -1,5 +1,9 @@
11 package net.curisit.securis;
22
3
+import java.io.File;
4
+
5
+import net.curisit.securis.utils.Params;
6
+
37 import org.apache.commons.cli.CommandLine;
48 import org.apache.commons.cli.CommandLineParser;
59 import org.apache.commons.cli.HelpFormatter;
....@@ -12,10 +16,47 @@
1216
1317 public class License {
1418
19
+ static {
20
+ // BasicConfigurator.configure(new ConsoleAppender());
21
+ // PropertyConfigurator.configure("/log4j.xml");
22
+ // LogManager.getRootLogger().
23
+ }
24
+
1525 private static final Logger log = LoggerFactory.getLogger(License.class);
1626
1727 public static void main(String[] args) {
28
+ log.info("Tool init");
29
+ checkConfigFile();
1830 CommandLine cmd = getCommandLine(args);
31
+
32
+ try {
33
+ if (cmd.hasOption('g')) {
34
+ String filename = cmd.getOptionValue("rfile");
35
+ if (filename == null)
36
+ filename = "./license.req";
37
+ LicenseManager.getInstance().createRequestFile(new File(filename));
38
+ System.exit(0);
39
+ }
40
+
41
+ } catch (SeCurisException e) {
42
+ log.error("The command generated an error: {}", e.toString());
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Checks that config file exists and contains mandatory parameters
48
+ */
49
+ private static void checkConfigFile() {
50
+ String appCode = Params.get(Params.KEYS.APPLICATION_CODE);
51
+ if (appCode == null) {
52
+ log.error("Manadatory parameter {} is not set in config file", Params.KEYS.APPLICATION_CODE);
53
+ System.exit(-3);
54
+ }
55
+ String customerCode = Params.get(Params.KEYS.CUSTOMER_CODE);
56
+ if (customerCode == null) {
57
+ log.error("Manadatory parameter {} is not set in config file", Params.KEYS.CUSTOMER_CODE);
58
+ System.exit(-4);
59
+ }
1960 }
2061
2162 private static CommandLine getCommandLine(String[] args) {
src/main/java/net/curisit/securis/SignatureHelper.java
....@@ -26,7 +26,6 @@
2626
2727 import org.apache.commons.io.FileUtils;
2828 import org.apache.commons.net.util.Base64;
29
-import org.apache.log4j.xml.DOMConfigurator;
3029 import org.slf4j.Logger;
3130 import org.slf4j.LoggerFactory;
3231
....@@ -130,7 +129,7 @@
130129
131130 public static void main(String[] args) throws SeCurisException {
132131 // org.apache.log4j.Logger.getRootLogger().addAppender(new Appender);
133
- DOMConfigurator.configure("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/src/main/resources/log4j.xml");
132
+ // DOMConfigurator.configure("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/src/main/resources/log4j.xml");
134133 RequestBean req = ReqGenerator.getInstance().createRequest("CI", "Roberto");
135134
136135 LicenseGenerator lg = LicenseGenerator.getInstance();
src/main/java/net/curisit/securis/utils/Params.java
....@@ -31,6 +31,7 @@
3131 loadParameters(KEY_CONFIG_FILE);
3232 } catch (IOException e) {
3333 log.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
34
+ System.exit(-2);
3435 }
3536 }
3637