[GEARPUMP-53] Output client logs to "logs/gearpump-client.log"

Author: manuzhang <owenzhang1990@gmail.com>

Closes #145 from manuzhang/log.
diff --git a/.travis.yml b/.travis.yml
index e47393c..82fffd7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
 language:
 - java
 - scala
-sudo: required
+sudo: false
 jdk:
 - oraclejdk8
 addons:
diff --git a/conf/log4j.properties b/conf/log4j.properties
index 32638e4..3f3ba89 100644
--- a/conf/log4j.properties
+++ b/conf/log4j.properties
@@ -39,6 +39,9 @@
 # Log file name for UI daemon process
 gearpump.ui.log.file=gearpump-ui-${JVM_NAME}.log
 
+# Log file name for client process
+gearpump.client.log.file=gearpump-client.log
+
 # The username of an application submitter, will be overwritten by Gearpump at runtime.
 gearpump.username=user
 # The application logger setting
diff --git a/core/src/main/resources/log4j.properties b/core/src/main/resources/log4j.properties
index cbe0749..c5c303b 100644
--- a/core/src/main/resources/log4j.properties
+++ b/core/src/main/resources/log4j.properties
@@ -35,6 +35,9 @@
 # Log file name for UI daemon process
 gearpump.ui.log.file=gearpump-ui-${JVM_NAME}.log
 
+# Log file name for client process
+gearpump.client.log.file=gearpump-client.log
+
 # The username of an application submitter, will be overwritten by Gearpump at runtime.
 gearpump.username=user
 # The application logger setting
diff --git a/core/src/main/scala/org/apache/gearpump/cluster/ClusterConfig.scala b/core/src/main/scala/org/apache/gearpump/cluster/ClusterConfig.scala
index fe8b761..adc8df3 100644
--- a/core/src/main/scala/org/apache/gearpump/cluster/ClusterConfig.scala
+++ b/core/src/main/scala/org/apache/gearpump/cluster/ClusterConfig.scala
@@ -90,9 +90,6 @@
         LOG.info("loading config file " + path + "..........")
         load(ClusterConfigSource(path))
       case None =>
-        if (configFile != null) {
-          LOG.info(s"loading config file $configFile...")
-        }
         load(ClusterConfigSource(configFile))
     }
   }
diff --git a/core/src/main/scala/org/apache/gearpump/cluster/main/AppSubmitter.scala b/core/src/main/scala/org/apache/gearpump/cluster/main/AppSubmitter.scala
index b2eef7d..81cfcbc 100644
--- a/core/src/main/scala/org/apache/gearpump/cluster/main/AppSubmitter.scala
+++ b/core/src/main/scala/org/apache/gearpump/cluster/main/AppSubmitter.scala
@@ -22,11 +22,9 @@
 import java.util.jar.JarFile
 
 import org.apache.gearpump.util.{AkkaApp, Constants, LogUtil, Util}
-import org.slf4j.Logger
 
 /** Tool to submit an application jar to cluster */
 object AppSubmitter extends AkkaApp with ArgumentsParser {
-  val LOG: Logger = LogUtil.getLogger(getClass)
 
   override val ignoreUnknownArgument = true
 
diff --git a/core/src/main/scala/org/apache/gearpump/cluster/main/Gear.scala b/core/src/main/scala/org/apache/gearpump/cluster/main/Gear.scala
index 1511469..b1737f7 100644
--- a/core/src/main/scala/org/apache/gearpump/cluster/main/Gear.scala
+++ b/core/src/main/scala/org/apache/gearpump/cluster/main/Gear.scala
@@ -17,19 +17,18 @@
  */
 package org.apache.gearpump.cluster.main
 
+import org.apache.gearpump.cluster.ClusterConfig
+import org.apache.gearpump.util.LogUtil.ProcessType
 import org.apache.gearpump.util.{Constants, LogUtil}
-import org.slf4j.Logger
 
 object Gear {
 
   val OPTION_CONFIG = "conf"
 
-  private val LOG: Logger = LogUtil.getLogger(getClass)
-
   val commands = Map("app" -> AppSubmitter, "kill" -> Kill,
     "info" -> Info, "replay" -> Replay, "main" -> MainRunner)
 
-  def usage(): Unit = {
+  def printUsage(): Unit = {
     val keys = commands.keys.toList.sorted
     // scalastyle:off println
     Console.err.println("Usage: " + "<" + keys.mkString("|") + ">")
@@ -37,10 +36,13 @@
   }
 
   private def executeCommand(command: String, commandArgs: Array[String]) = {
-    commands.get(command).map(_.main(commandArgs))
-    if (!commands.contains(command)) {
-      val allArgs = (command +: commandArgs.toList).toArray
-      MainRunner.main(allArgs)
+    commands.get(command) match {
+      case Some(runner) =>
+        val akkaConfig = ClusterConfig.default()
+        LogUtil.loadConfiguration(akkaConfig, ProcessType.CLIENT)
+        runner.main(akkaConfig, commandArgs)
+      case None =>
+        printUsage()
     }
   }
 
@@ -52,7 +54,7 @@
     }
 
     if (args.length == 0) {
-      usage()
+      printUsage()
     } else {
       val command = args(0)
       val commandArgs = args.drop(1)
diff --git a/core/src/main/scala/org/apache/gearpump/cluster/main/Info.scala b/core/src/main/scala/org/apache/gearpump/cluster/main/Info.scala
index e1fe291..e2f8bad 100644
--- a/core/src/main/scala/org/apache/gearpump/cluster/main/Info.scala
+++ b/core/src/main/scala/org/apache/gearpump/cluster/main/Info.scala
@@ -25,8 +25,6 @@
 /** Tool to query master info */
 object Info extends AkkaApp with ArgumentsParser {
 
-  private val LOG: Logger = LogUtil.getLogger(getClass)
-
   override val options: Array[(String, CLIOption[Any])] = Array(
     // For document purpose only, OPTION_CONFIG option is not used here.
     // OPTION_CONFIG is parsed by parent shell command "Gear" transparently.
diff --git a/core/src/main/scala/org/apache/gearpump/cluster/main/Kill.scala b/core/src/main/scala/org/apache/gearpump/cluster/main/Kill.scala
index 8ecaf85..4f07707 100644
--- a/core/src/main/scala/org/apache/gearpump/cluster/main/Kill.scala
+++ b/core/src/main/scala/org/apache/gearpump/cluster/main/Kill.scala
@@ -25,8 +25,6 @@
 /** Tool to kill an App */
 object Kill extends AkkaApp with ArgumentsParser {
 
-  private val LOG: Logger = LogUtil.getLogger(getClass)
-
   override val options: Array[(String, CLIOption[Any])] = Array(
     "appid" -> CLIOption("<application id>", required = true),
     // For document purpose only, OPTION_CONFIG option is not used here.
@@ -41,7 +39,6 @@
 
     if (null != config) {
       val client = ClientContext(akkaConf)
-      LOG.info("Client ")
       client.shutdown(config.getInt("appid"))
       client.close()
     }
diff --git a/core/src/main/scala/org/apache/gearpump/cluster/main/MainRunner.scala b/core/src/main/scala/org/apache/gearpump/cluster/main/MainRunner.scala
index 8664232..42c2081 100644
--- a/core/src/main/scala/org/apache/gearpump/cluster/main/MainRunner.scala
+++ b/core/src/main/scala/org/apache/gearpump/cluster/main/MainRunner.scala
@@ -23,7 +23,6 @@
 
 /** Tool to run any main class by providing a jar */
 object MainRunner extends AkkaApp with ArgumentsParser {
-  private val LOG: Logger = LogUtil.getLogger(getClass)
 
   override val options: Array[(String, CLIOption[Any])] = Array(
     // For document purpose only, OPTION_CONFIG option is not used here.
diff --git a/core/src/main/scala/org/apache/gearpump/cluster/main/Replay.scala b/core/src/main/scala/org/apache/gearpump/cluster/main/Replay.scala
index e648d61..03ec899 100644
--- a/core/src/main/scala/org/apache/gearpump/cluster/main/Replay.scala
+++ b/core/src/main/scala/org/apache/gearpump/cluster/main/Replay.scala
@@ -24,8 +24,6 @@
 // Internal tool to restart an application
 object Replay extends AkkaApp with ArgumentsParser {
 
-  private val LOG: Logger = LogUtil.getLogger(getClass)
-
   override val options: Array[(String, CLIOption[Any])] = Array(
     "appid" -> CLIOption("<application id>", required = true),
     // For document purpose only, OPTION_CONFIG option is not used here.
diff --git a/core/src/main/scala/org/apache/gearpump/util/LogUtil.scala b/core/src/main/scala/org/apache/gearpump/util/LogUtil.scala
index 225f796..1897ca4 100644
--- a/core/src/main/scala/org/apache/gearpump/util/LogUtil.scala
+++ b/core/src/main/scala/org/apache/gearpump/util/LogUtil.scala
@@ -30,7 +30,7 @@
 object LogUtil {
   object ProcessType extends Enumeration {
     type ProcessType = Value
-    val MASTER, WORKER, LOCAL, APPLICATION, UI = Value
+    val MASTER, WORKER, LOCAL, APPLICATION, UI, CLIENT = Value
   }
 
   def getLogger[T](
diff --git a/core/src/test/scala/org/apache/gearpump/cluster/main/MainSpec.scala b/core/src/test/scala/org/apache/gearpump/cluster/main/MainSpec.scala
index 0ad6883..29fcd26 100644
--- a/core/src/test/scala/org/apache/gearpump/cluster/main/MainSpec.scala
+++ b/core/src/test/scala/org/apache/gearpump/cluster/main/MainSpec.scala
@@ -168,22 +168,5 @@
       local.destroy()
     }
   }
-
-  "Gear" should "support app|info|kill|shell|replay" in {
-
-    val commands = Array("app", "info", "kill", "shell", "replay")
-
-    assert(Try(Gear.main(Array.empty)).isSuccess, "print help, no throw")
-
-    for (command <- commands) {
-      assert(Try(Gear.main(Array("-noexist"))).isFailure,
-        "pass unknown option, throw, command: " + command)
-    }
-
-    assert(Try(Gear.main(Array("unknownCommand"))).isFailure, "unknown command, throw ")
-
-    val tryThis = Try(Gear.main(Array("unknownCommand", "-noexist")))
-    assert(tryThis.isFailure, "unknown command, throw")
-  }
 }