ifm3d::Logger - Logger for the ifm3d library

The ifm3d::Logger is a powerful logging utility designed to facilitate effective logging within the ifm3d library and applications. It allows users to control log levels and define custom log writers (sinks) for handling log messages.

Log Levels

The ifm3d::Logger library supports the following log levels:

class LogLevel():
    None
    Critical
    Error
    Info
    Warning
    Debug
    Verbose
  • None: No logging is done.

  • Critical: Indicates a critical error that may cause the application to terminate.

  • Error: Indicates an error that caused the application to fail to perform a specific function or operation.

  • Warning: Indicates potential issues that do not prevent the application from functioning.

  • Info: General information about the application’s operation.

  • Debug: Detailed information for debugging purposes.

  • Verbose: Logs with internal values for debugging purposes.

By default, the log level is set to Warning, which means all log messages of Warning, Error, and Critical will be recorded. However, users can configure the log level to control which messages are logged.

from ifm3dpy.logging import Logger, LogLevel, LogWriter, LogFormatterText, LogEntry

# Define a custom LogWriter
class MyLogWriter(LogWriter):
    def write(self, entry: LogEntry) -> None:
        print("Logging from python: ", LogFormatterText.format(entry))

# Create the MyLogWriter instance
MY_LOGGER = MyLogWriter()

if __name__ == "__main__":
  # Set a log level
  Logger.set_writer(LogLevel.Error)

  # Assign the LogWriter instance
  Logger.set_writer(MY_LOGGER)

  # Do something that causes a log message to happen
  o3r = ifm3dpy.O3R()
  o3r.port("non-existing-port")

Warning

Due to a known issue with the third party tool pybind11, the user needs to ensure that the instance of the logger is kept alive throughout the whole execution of the script.