@@ -32,8 +32,9 @@ import animatedledstrip.leds.AnimatedLEDStrip
3232import animatedledstrip.leds.emulated.EmulatedAnimatedLEDStrip
3333import animatedledstrip.utils.delayBlocking
3434import org.apache.commons.cli.DefaultParser
35- import org.tinylog.Logger
36- import org.tinylog.configuration.Configuration
35+ import org.pmw.tinylog.Configurator
36+ import org.pmw.tinylog.Level
37+ import org.pmw.tinylog.Logger
3738import java.io.File
3839import java.io.FileInputStream
3940import java.io.FileNotFoundException
@@ -66,16 +67,19 @@ class AnimatedLEDStripServer<T : AnimatedLEDStrip>(
6667
6768 val loggingLevel =
6869 when {
69- cmdline.hasOption(" t" ) -> " trace "
70- cmdline.hasOption(" d" ) -> " debug "
71- cmdline.hasOption(" q" ) -> " off "
72- else -> " info "
70+ cmdline.hasOption(" t" ) -> Level . TRACE
71+ cmdline.hasOption(" d" ) -> Level . DEBUG
72+ cmdline.hasOption(" q" ) -> Level . OFF
73+ else -> Level . INFO
7374 }
7475
75- Configuration .set(" level" , loggingLevel)
76- Configuration .set(" format" , loggingPattern)
76+ Configurator .defaultConfig().formatPattern(loggingPattern).level(loggingLevel).addWriter(SocketWriter ())
77+ .activate()
78+
79+
7780 }
78- private val properties = Properties ().apply {
81+
82+ private val properties: Properties ? = Properties ().apply {
7983 try {
8084 load(FileInputStream (propertyFileName))
8185 } catch (e: FileNotFoundException ) {
@@ -87,22 +91,22 @@ class AnimatedLEDStripServer<T : AnimatedLEDStrip>(
8791
8892 private val emulated: Boolean = cmdline.hasOption(" e" ) || cmdline.hasOption(" E" )
8993
90- private val numLEDs: Int = properties.getProperty(" numLEDs" , " 240" ).toInt()
94+ private val numLEDs: Int = properties? .getProperty(" numLEDs" , " 240" )? .toInt() ? : 240
9195
92- private val pin: Int = properties.getProperty(" pin" , " 12" ).toInt()
96+ private val pin: Int = properties? .getProperty(" pin" , " 12" )? .toInt() ? : 12
9397
9498 private val imageDebuggingEnabled: Boolean = cmdline.hasOption(" i" )
9599
96100 private val ports = mutableListOf<Int >().apply {
97- properties.getProperty(" ports" )?.split(' ' )?.forEach {
101+ properties? .getProperty(" ports" )?.split(' ' )?.forEach {
98102 requireNotNull(it.toIntOrNull())
99103 this .add(it.toInt())
100104 }
101105 if (! emulated) this + = 1118 // local port
102106 }
103107
104108 private val rendersBeforeSave =
105- properties.getProperty(" renders" )?.toIntOrNull() ? : cmdline.getOptionValue(" r" )?.toIntOrNull() ? : 1000
109+ properties? .getProperty(" renders" )?.toIntOrNull() ? : cmdline.getOptionValue(" r" )?.toIntOrNull() ? : 1000
106110
107111 private val leds = when (emulated) {
108112 false -> ledClass.primaryConstructor!! .call(
@@ -119,7 +123,10 @@ class AnimatedLEDStripServer<T : AnimatedLEDStrip>(
119123 )
120124 }
121125
122- internal val animationHandler = AnimationHandler (leds)
126+ private val persistAnimations =
127+ properties?.getProperty(" persist" , " false" )?.toBoolean() ? : cmdline.hasOption(" P" )
128+
129+ internal val animationHandler = AnimationHandler (leds, persistAnimations = persistAnimations)
123130
124131 var testAnimation: AnimationData =
125132 AnimationData ().animation(Animation .COLOR ).color(CCBlue )
@@ -155,6 +162,18 @@ class AnimatedLEDStripServer<T : AnimatedLEDStrip>(
155162 Logger .info { " Shutting down server" }
156163 stop()
157164 }
165+ " DEBUG" -> {
166+ setLoggingLevel(Level .DEBUG )
167+ Logger .debug(" Set logging level to debug" )
168+ }
169+ " TRACE" -> {
170+ setLoggingLevel(Level .TRACE )
171+ Logger .trace(" Set logging level to trace" )
172+ }
173+ " INFO" -> {
174+ setLoggingLevel(Level .INFO )
175+ Logger .info(" Set logging level to info" )
176+ }
158177 " CLEAR" -> {
159178 animationHandler.addAnimation(AnimationData ().animation(Animation .COLOR ))
160179 }
@@ -179,4 +198,8 @@ class AnimatedLEDStripServer<T : AnimatedLEDStrip>(
179198 }
180199 }
181200
201+ private fun setLoggingLevel (level : Level ) {
202+ Configurator .currentConfig().level(level).activate()
203+ }
204+
182205}
0 commit comments