Permalink
Browse files

Now log4j is configurable.

  • Loading branch information...
lpm11 committed Feb 17, 2012
1 parent c8118f8 commit 5d164482eabf07db7e46a559501b0b3097b24133
Showing with 23 additions and 0 deletions.
  1. +15 −0 log4j.xml
  2. +8 −0 src/main/java/AppBase.java
View
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="stderr" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.err" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d %5p %c{1} - %m%n"/>
+ </layout>
+ </appender>
+
+ <root>
+ <level value="error" />
+ <appender-ref ref="stderr" />
+ </root>
+</log4j:configuration>
@@ -2,6 +2,8 @@
import joptsimple.OptionSet;
import org.msgpack.rpc.Server;
import org.msgpack.rpc.loop.EventLoop;
+import org.apache.log4j.xml.DOMConfigurator;
+import java.io.File;
public class AppBase {
/**
@@ -11,8 +13,14 @@ public static void main(String[] args) throws Exception {
OptionParser optparse = new OptionParser();
optparse.accepts("port","Listen port.").withRequiredArg();
optparse.accepts("lm","Language model file name.").withRequiredArg();
+ optparse.accepts("log4j","log4j configuration file.").withRequiredArg();
OptionSet opt = optparse.parse(args);
+ File file = new File("log4j.xml");
+ if (opt.has("log4j") || file.exists()) {
+ DOMConfigurator.configure(opt.has("log4j") ? (String)opt.valueOf("log4j"):"log4j.xml");
+ }
+
KylmServer ks = new KylmServer((String)opt.valueOf("lm"));
EventLoop loop = EventLoop.defaultEventLoop();

0 comments on commit 5d16448

Please sign in to comment.