11package io.github.iamnicknack.pi4j.grpc.server
22
3+ import ch.qos.logback.classic.Level
4+ import ch.qos.logback.classic.LoggerContext
35import io.github.iamnicknack.pi4j.grpc.server.config.ServerContext
46import io.github.iamnicknack.pi4j.grpc.server.config.args.CommandLineArgument
57import io.github.iamnicknack.pi4j.grpc.server.config.args.CommandLineParser
8+ import org.slf4j.LoggerFactory
69
710private val pluginArg = CommandLineArgument (
811 " plugin" ,
@@ -26,6 +29,11 @@ private val proxyPortArg = CommandLineArgument(
2629 systemProperty = ServerContext .PROXY_PORT_PROPERTY ,
2730 description = " The port of the remote pi4j server when running as a proxy"
2831)
32+ private val debugArg = CommandLineArgument (
33+ " debug" ,
34+ isFlag = true ,
35+ description = " Additional logging of IO activity"
36+ )
2937private val helpArg = CommandLineArgument (
3038 " help" ,
3139 isFlag = true ,
@@ -37,15 +45,29 @@ private val parser = CommandLineParser.Builder()
3745 .arg(portArg)
3846 .arg(proxyHostArg)
3947 .arg(proxyPortArg)
48+ .arg(debugArg)
4049 .arg(helpArg)
4150 .build()
4251
52+ /* *
53+ * Allow the log level to be set based on command line arguments
54+ */
55+ fun setServiceLogLevel (level : String ) {
56+ val ctx = LoggerFactory .getILoggerFactory() as LoggerContext
57+ ctx.getLogger(" io.github.iamnicknack.pi4j.grpc" ).level = Level .toLevel(level)
58+
59+ }
60+
4361fun main (args : Array <String >) {
4462 val commandLineArgs = parser.parse(args)
4563
4664 if (commandLineArgs.flag(helpArg.name)) {
4765 parser.help(System .out )
4866 } else {
67+ if (commandLineArgs.flag(debugArg.name)) {
68+ setServiceLogLevel(" DEBUG" )
69+ }
70+
4971 ServerContext (
5072 commandLineArgs.value<String >(pluginArg.name),
5173 commandLineArgs.value<Int >(portArg.name),
0 commit comments