smartinspectpython.siconfigurationtimer

@export
class SIConfigurationTimer:

Monitors a SmartInspect configuration settings file for changes and reloads the configuration when it does.

A watchdog Observer class is used to monitor the configuration filepath for changes (create, update, delete).

The SmartInspect.LoadConfiguration method is called if the configuration filepath is created or changed.

The SmartInspect.Enabled property is set to False if the configuration filepath is deleted (e.g. disables SmartInspect logging).

For information about SmartInspect configuration files, please refer to the documentation of the SmartInspect.LoadConfiguration method.

Threadsafety:

This class is fully thread-safe.

Sample Code

# package imports.
from smartinspectpython.siauto import *

# load SmartInspect settings from a configuration settings file.
siConfigPath:str = "./smartinspect.cfg"
SIAuto.Si.LoadConfiguration(siConfigPath)

# start monitoring the configuration file for changes, and reload it when it changes.
siConfigTask:SIConfigurationTimer = SIConfigurationTimer(SIAuto.Si, siConfigPath)

# get smartinspect logger reference.
logsi:SISession = SIAuto.Main


The following is the configuration settings file contents:

; smartinspect.cfg

; SmartInspect Logging Configuration General settings.
; - "Enabled" parameter to turn logging on (True) or off (False).
; - "Level" parameter to control the logging level (Debug|Verbose|Message|Warning|Error).
; - "AppName" parameter to control the application name.
Enabled = False 
Level = Verbose
DefaultLevel = Debug
AppName = My Application Name

; SmartInspect Logging Configuration Output settings.
; - Log to SmartInspect Console Viewer running on the specified network address.
Connections = tcp(host=localhost, port=4228, timeout=5000, reconnect=true, reconnect.interval=10s, async.enabled=true)
; - Log to a file:
;Connections = "file(filename=\"./tests/logfiles/logfile.log\", rotate=hourly, maxparts=24, append=true)"
; - Log to an encrypted file:
;Connections = "file(filename=\"./tests/logfiles/logfileEncrypted.sil\", encrypt=true, key=""1234567890123456"", rotate=hourly, maxparts=14, append=true)"

; set defaults for new sessions
; note that session defaults do not apply to the SIAuto.Main session, since
; this session was already added before a configuration file can be loaded. 
; session defaults only apply to newly added sessions and do not affect existing sessions.
SessionDefaults.Active = True
SessionDefaults.Level = Message
SessionDefaults.ColorBG = 0xFFFFFF

; configure some individual session properties.
; note that this does not add the session to the sessionmanager; it simply
; sets the property values IF the session name already exists.
Session.Main.Active = True
Session.Main.ColorBG = 0xFFFFFF

SIConfigurationTimer( smartInspect: smartinspectpython.smartinspect.SmartInspect, filePath: str)

Initializes a new instance of the class.

Arguments:
  • smartInspect (SmartInspect): The SmartInspect object to configure.
  • filePath (str): The path of the configuration file to monitor.
Raises:
  • SIArgumentNullException: The smartInspect or filePath parameter is null.

The monitoring of the file begins immediately.

def Start(self) -> None:

Starts monitoring the configuration file for changes.

This method is called automatically when a new instance of the class is created. It can also be called after issuing a "Stop" method call, to restart monitoring of the configuration file.

It will start a new thread named "SiConfigFileMonitorTask" that will execute the watchdog Observer that monitors the specified configuration filepath for changes.

def Stop(self) -> None:

Stops monitoring the configuration file for changes.