@@ -37,8 +37,7 @@ import cz.vutbr.fit.interlockSim.util.Util
3737import jDisco.DiscoException
3838import jDisco.Process
3939import jDisco.Random
40- import org.slf4j.Logger
41- import org.slf4j.LoggerFactory
40+ import io.github.oshai.kotlinlogging.KotlinLogging
4241import java.beans.PropertyChangeSupport
4342import java.util.ArrayList
4443import java.util.Collection
@@ -122,14 +121,13 @@ abstract class DefaultContext :
122121 /* *
123122 * Logger for general class operations.
124123 */
125- private val logger: Logger = LoggerFactory .getLogger( DefaultContext :: class .java)
124+ private val logger = KotlinLogging .logger {}
126125
127126 /* *
128127 * Separate logger for simulation events to allow independent level control.
129128 * Configured in logback.xml as "cz.vutbr.fit.interlockSim.simulation".
130129 */
131- private val simulationLogger: Logger =
132- LoggerFactory .getLogger(" cz.vutbr.fit.interlockSim.simulation" )
130+ private val simulationLogger = KotlinLogging .logger(" cz.vutbr.fit.interlockSim.simulation" )
133131
134132 /* *
135133 * Constant - square root of 2
@@ -140,7 +138,7 @@ abstract class DefaultContext :
140138
141139 protected constructor (cols: Int , rows: Int ) {
142140 this .railwayNetGrid = DefaultRailWayNetGrid (cols, rows)
143- logger.debug( " Initialized railway network grid: {}x{ } cells" , cols, rows)
141+ logger.debug { " Initialized railway network grid: ${cols} x ${rows } cells" }
144142 }
145143
146144 override fun getRailWayNetGrid (): DefaultRailWayNetGrid = railwayNetGrid
@@ -461,13 +459,9 @@ abstract class DefaultContext :
461459 val lineParts = findTrackLineParts(key1, key2, trackBlock)
462460
463461 if (lineParts == null || lineParts.isEmpty()) {
464- logger.debug(
465- " Join failed between ({},{}) and ({},{})" ,
466- key1.x,
467- key1.y,
468- key2.x,
469- key2.y
470- )
462+ logger.debug {
463+ " Join failed between (${key1.x} ,${key1.y} ) and (${key2.x} ,${key2.y} )"
464+ }
471465 changeSupport.firePropertyChange(
472466 ContextChangeListener .JOIN_FAILED ,
473467 null ,
@@ -483,14 +477,9 @@ abstract class DefaultContext :
483477 }
484478
485479 val mapSize = (lineParts as ? MutableMap <Point , TrackBlockPart >)?.size ? : 0
486- logger.debug(
487- " Created track join ({},{})->({},{}) with {} intermediate cells" ,
488- key1.x,
489- key1.y,
490- key2.x,
491- key2.y,
492- mapSize
493- )
480+ logger.debug {
481+ " Created track join (${key1.x} ,${key1.y} )->(${key2.x} ,${key2.y} ) with $mapSize intermediate cells"
482+ }
494483 changeSupport.firePropertyChange(
495484 ContextChangeListener .JOIN_CREATED ,
496485 null ,
@@ -543,9 +532,7 @@ abstract class DefaultContext :
543532 }
544533 if (nodeCell is InOut ) getInOuts().add(nodeCell as InOut )
545534 changeSupport.firePropertyChange(ContextChangeListener .CELL_ADDED , null , key)
546- if (logger.isTraceEnabled()) {
547- logger.trace(" Added {} at ({},{})" , nodeCell.javaClass.simpleName, key.x, key.y)
548- }
535+ logger.trace { " Added ${nodeCell.javaClass.simpleName} at (${key.x} ,${key.y} )" }
549536 }
550537
551538 /* *
@@ -742,12 +729,8 @@ abstract class DefaultContext :
742729
743730 @Suppress(" UNCHECKED_CAST" )
744731 val result = nextTrackBlock?.getNextTrackSection(nodeCell, null as TrackSection ? )
745- if (logger.isTraceEnabled()) {
746- logger.trace(
747- " getNextTrackSection: navigating network from {}, result: {}" ,
748- separator,
749- if (result != null ) " found" else " not found"
750- )
732+ logger.trace {
733+ " getNextTrackSection: navigating network from $separator , result: ${if (result != null ) " found" else " not found" } "
751734 }
752735 return result
753736 }
@@ -758,22 +741,19 @@ abstract class DefaultContext :
758741 @Throws(EmptyContextException ::class , SimulationException ::class )
759742 override fun run () {
760743 if (getGraph().isEmpty() || getGrid().isEmpty() || inouts.isEmpty()) {
761- logger.warn(
762- " Cannot start simulation: graph={}, grid={}, inouts={}" ,
763- if (getGraph().isEmpty()) " empty" else " ok" ,
764- if (getGrid().isEmpty()) " empty" else " ok" ,
765- if (inouts.isEmpty()) " empty" else " ok"
766- )
744+ logger.warn {
745+ " Cannot start simulation: graph=${if (getGraph().isEmpty()) " empty" else " ok" } , " +
746+ " grid=${if (getGrid().isEmpty()) " empty" else " ok" } , " +
747+ " inouts=${if (inouts.isEmpty()) " empty" else " ok" } "
748+ }
767749 throw EmptyContextException ()
768750 }
769751 if (mainProcess == null ) mainProcess = Generator (this )
770752
771- logger.info(
772- " Starting simulation: {} InOut points, {} track blocks, main process={}" ,
773- inouts.size,
774- getGraph().size(),
775- mainProcess!! .javaClass.simpleName
776- )
753+ logger.info {
754+ " Starting simulation: ${inouts.size} InOut points, ${getGraph().size()} track blocks, " +
755+ " main process=${mainProcess!! .javaClass.simpleName} "
756+ }
777757
778758 for (i in inouts) {
779759 workers[i] = InOutWorker (this , i)
@@ -782,7 +762,7 @@ abstract class DefaultContext :
782762 try {
783763 Process .activate(mainProcess)
784764 } catch (e: DiscoException ) {
785- logger.error(" Failed to activate main simulation process" , e)
765+ logger.error(e) { " Failed to activate main simulation process" }
786766 throw SimulationException (e)
787767 }
788768 }
@@ -854,9 +834,7 @@ abstract class DefaultContext :
854834 if (sep == null || nxt == null ) {
855835 throw IllegalArgumentException (" wrong arguments for aPath finding" )
856836 }
857- if (logger.isDebugEnabled()) {
858- logger.debug(" pathToNextSemaphore: searching path from {} via track section" , sep)
859- }
837+ logger.debug { " pathToNextSemaphore: searching path from $sep via track section" }
860838 var separator = sep
861839 var previous: TrackSection ? = null
862840 var next: TrackSection ? = nxt
@@ -874,14 +852,12 @@ abstract class DefaultContext :
874852 if (separator is OrientedPathSeparator ) {
875853 if (isSeparatorInDirection(separator, next, previous)) {
876854 path.add(separator)
877- if (logger.isTraceEnabled()) {
878- logger.trace(" pathToNextSemaphore: found complete path with length {}" , path.length())
879- }
855+ logger.trace { " pathToNextSemaphore: found complete path with length ${path.length()} " }
880856 return path
881857 }
882858 }
883859 } while (next != null )
884- logger.debug( " pathToNextSemaphore: no path found from {} " , sep)
860+ logger.debug { " pathToNextSemaphore: no path found from $sep " }
885861 return null
886862 }
887863
@@ -918,7 +894,6 @@ abstract class DefaultContext :
918894 type : ReportType
919895 ) {
920896 if (! isReporting(type)) return
921- if (! simulationLogger.isInfoEnabled()) return
922897
923898 val buf = if (report is StringBuilder ) report else StringBuilder (report)
924899 try {
@@ -927,11 +902,11 @@ abstract class DefaultContext :
927902 buf.insert(0 , obj)
928903 }
929904 } catch (e: Exception ) {
930- logger.error(" Error generating simulation report for type {} " , type, e)
905+ logger.error(e) { " Error generating simulation report for type $type " }
931906 }
932907 buf.insert(0 , ' ' )
933908 buf.insert(0 , jDisco.Process .time())
934- simulationLogger.info( " {} " , buf)
909+ simulationLogger.info { buf }
935910 }
936911
937912 /* *
0 commit comments