Skip to content

[Known issue] RuntimeError when custom python LogWriter is dropped. #448

@BigBoot

Description

@BigBoot

Describe the bug

If a custom python LogWriter object is set and dropped, the next logging output will lead to a RuntimeError: Tried to call pure virtual function "ifm3d::LogWriter::write" error. To ensure the logging works as expected the custom python LogWriter instance needs to be kept alive for the whole Lifetime of the program.

To Reproduce

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

if __name__ == "__main__":
    # The python instance will be dropped after the set_writer method returns leading to a RuntimeError on the next logging call
    Logger.set_writer(MyLogWriter())

Workaround

Ensure the python LogWriter instance stays valid for the whole runtime of the application:

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

# Create a global MyLogWriter instance
MY_LOGGER = MyLogWriter()

if __name__ == "__main__":
  # Assign the LogWriter instance
  Logger.set_writer(MY_LOGGER)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugno-staleIssue will not be marked as stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions