Manage Logs¶
The Inscoper API provides a configurable logging system that captures internal events generated by the bridge and the hardware drivers. Logging is initialized through a single call to initLogger(), which must be made before any other bridge operations to ensure that all output — including device initialization messages — is captured.
Overview¶
The logger accepts two configuration parameters: a mode that determines where log output is sent, and a level that filters the verbosity of the output.
Log modes¶
| Mode | Description |
|---|---|
ELogMode_FILE |
Writes log output to a file on disk |
ELogMode_CONSOLE |
Writes log output to the standard output stream |
ELogMode_LISTENER |
Delivers log entries to a registered LogListener callback |
ELogMode_ALL |
Combines all output targets simultaneously |
Log levels¶
Log levels control the minimum severity of messages that are captured. Common values include ELogLevel_LOG_ALL (captures everything) and ELogLevel_LOG_ERROR (captures errors only). Refer to the API reference for the complete list of available levels.
Log to a file¶
Initialize the logger in file mode by passing ELogMode_FILE and a target filename to initLogger(). All log entries generated during the session are written to the specified file.
import os
import inscoper_api
# Macro to all Inscoper configurations
CONFIG_PATH = os.environ['InscoperConfigsPath']
my_bridge = inscoper_api.Bridge()
# Initialize the logging system.
# First argument is the log mode, among ELogMode_FILE, ELogMode_CONSOLE, ELogMode_LISTENER, and ELogMode_ALL
# Second argument is the log level (ALL, ERROR, TRACE...)
my_bridge.initLogger(inscoper_api.ELogMode_FILE, inscoper_api.ELogLevel_LOG_ALL, filename="api.log")
my_bridge.loadConfigFile(os.sep.join([CONFIG_PATH, "singleCamera"]))
my_bridge.initDevices()
my_bridge.close()
Log through a listener¶
Initialize the logger in listener mode by registering a custom subclass of LogListener. The logFunction() callback receives each log entry as it is generated, along with its severity level, allowing the application to route, filter, or display log output programmatically.
Note
The listener instance must be created and held in a variable before being passed to initLogger(). Passing a newly constructed listener directly in the call may cause it to be collected before any log entries are delivered.
import os
import inscoper_api
# Macro to all Inscoper configurations
CONFIG_PATH = os.environ['InscoperConfigsPath']
# Define a custom log listener
class CustomLogListener(inscoper_api.LogListener):
def __init__(self):
super().__init__()
def logFunction(self, message, level):
print(f"Received message: {message}, level: {level}")
# Instantiate the log listener (do not instantiate it directly in the initLogger call)
my_listener = CustomLogListener()
my_bridge = inscoper_api.Bridge()
# Initialize the logging system.
# First argument is the log mode, among ELogMode_FILE, ELogMode_CONSOLE, ELogMode_LISTENER, and ELogMode_ALL
# Second argument is the log level (ALL, ERROR, TRACE...)
my_bridge.initLogger(inscoper_api.ELogMode_LISTENER, inscoper_api.ELogLevel_LOG_ALL, listener=my_listener)
my_bridge.loadConfigFile(os.sep.join([CONFIG_PATH, "singleCamera"]))
my_bridge.initDevices()
# my_bridge.removeLogListener(my_listener)
my_bridge.close()