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)
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
Workaround
Ensure the python LogWriter instance stays valid for the whole runtime of the application: