Skip to content

Commit 576c52f

Browse files
authored
Merge pull request #6 from IAmNickNack/develop
2 parents 0725512 + a222d25 commit 576c52f

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎pi4j-plugin-grpc-server/build.gradle.kts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
implementation(libs.pi4j.core)
1515
implementation(libs.pi4j.plugin.ffm)
1616
implementation(libs.pi4j.plugin.mock)
17-
runtimeOnly(libs.logback.classic)
17+
implementation(libs.logback.classic)
1818
testImplementation(libs.grpc.testing)
1919
}
2020

‎pi4j-plugin-grpc-server/src/main/kotlin/io/github/iamnicknack/pi4j/grpc/server/Pi4jGrpc.kt‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package io.github.iamnicknack.pi4j.grpc.server
22

3+
import ch.qos.logback.classic.Level
4+
import ch.qos.logback.classic.LoggerContext
35
import io.github.iamnicknack.pi4j.grpc.server.config.ServerContext
46
import io.github.iamnicknack.pi4j.grpc.server.config.args.CommandLineArgument
57
import io.github.iamnicknack.pi4j.grpc.server.config.args.CommandLineParser
8+
import org.slf4j.LoggerFactory
69

710
private 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+
)
2937
private 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+
4361
fun 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),

‎pi4j-plugin-grpc-server/src/main/resources/logback.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
</root>
1313

1414
<logger name="com.pi4j" level="INFO" />
15-
<logger name="io.github.iamnicknack" level="DEBUG" />
15+
<logger name="io.github.iamnicknack.pi4j.grpc" level="INFO" />
1616
</configuration>

0 commit comments

Comments
 (0)