One function

add_file_handler in colcon/colcon-core

The author described this change as Fix modified logger in add_file_handler, add tests (#649). It counts as a record because the check below fails on the code as it stood at b17460865 and passes on a067589eb, with nothing else changed between the two runs.

Fix saved2024-05-24
Sharing licenceApache-2.0 · LICENSE
Change size+5 5

What the code was meant to do, written into the code itself as a docstring

Add a file handler to the logger which logs messages of all levels. :param logger: The logger to add the file handler to :param path: The path of the generated log file :returns: The added file handler :rtype: logging.FileHandler

The change

2727 if isinstance(handler, logging.StreamHandler):
2828 formatter = handler.formatter
2929 # filter colcon specific log messages from default stream handler
30- handler.addFilter(Filter(colcon_logger.name))
30+ handler.addFilter(Filter(logger.name))
3131
3232 # add a stream handler replacing the one filtered on the root logger
3333 handler = logging.StreamHandler()
3434 if formatter:
3535 # use same formatter as for stream handler
3636 handler.setFormatter(formatter)
37- handler.setLevel(colcon_logger.getEffectiveLevel())
38- colcon_logger.addHandler(handler)
37+ handler.setLevel(logger.getEffectiveLevel())
38+ logger.addHandler(handler)
3939
4040 # add a file handler writing all log levels
4141 handler = logging.FileHandler(str(path))
5353 # use same formatter as for stream handler
5454 handler.setFormatter(formatter)
5555 handler.setLevel(1)
56- colcon_logger.addHandler(handler)
56+ logger.addHandler(handler)
5757
5858 # change the logger to handle all levels
59- colcon_logger.setLevel(1)
59+ logger.setLevel(1)
6060
6161 return handler

The check that tells the two apart

failpass·test/test_logging.py::test_add_file_handler

Check file test/test_logging.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itb174608650a3521203e10d7950aa35a3c6d63dcc
Broken version dated2024-05-24
Modulecolcon_core.logging
Units changedadd_file_handler
Fingerprint6de85c38ed94d078
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in colcon/colcon-core