smartinspectpython.siauto

Module: siauto.py

Revision History

Date Version Description
2023/09/27 3.0.21.0 Updated documentation sample code and examples.
2023/05/30 3.0.0.0 Initial Version.

Provides automatically created objects for using SmartInspect Python logging.

The following classes are imported when from smartinspectpython.siauto import * is specified:

  • SIArgumentNullException
  • SIArgumentOutOfRangeException
  • SIAuto
  • SIColors
  • SIConfigurationTimer
  • SIControlCommandEventArgs
  • SIErrorEventArgs
  • SIFilterEventArgs
  • SIInfoEventArgs
  • SILevel
  • SILogEntryEventArgs
  • SIMethodParmListContext
  • SIProcessFlowEventArgs
  • SISession
  • SIWatchEventArgs
  • SmartInspectException
@static_init
class SIAuto:

Provides automatically created objects for using the SmartInspect and SISession classes.

This class provides a static property called Si of type SmartInspect. Furthermore a SISession instance named Main with Si as parent is ready to use. The siauto module is especially useful if you do not want to create SmartInspect and SISession instances by yourself.

The SmartInspect.Connections property of Si is set to "tcp(host=localhost)", the SmartInspect.AppName property to "Auto" and the SISession.Name property to "Main".

Threadsafety:

The public static members of this class are thread-safe.

Sample Code

# package imports.
from smartinspectpython.siauto import *

#############################################################################
# Use the following for 1-time initialization code:
#############################################################################

# 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)

#############################################################################
# Use the following in main (or classes) in your project:
#############################################################################

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

# log some messages and data.
_logsi.LogSystem(SILevel.Debug)
_logsi.LogDebug("This is a Debug message.")
_logsi.LogMessage("This is a Message.")
_logsi.LogWarning("You have been warned!")
_logsi.LogError("Danger Will Robinson!")


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

SmartInspect logging instance (automatically created).

SmartInspect logging Session instance ('Main', automatically created).

The SISession.Name is set to "Main" and the SISession.Parent to SIAuto.Si.

Sample Code

# package imports.
from smartinspectpython.siauto import *

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

# log some messages and data.
_logsi.LogSystem(SILevel.Debug)
_logsi.LogDebug("This is a Debug message.")
_logsi.LogMessage("This is a Message.")
_logsi.LogWarning("You have been warned!")
_logsi.LogError("Danger Will Robinson!")

@classmethod
def static_init(cls) -> None:

Initializes a new static instance of the class.