Skip to content

Function name and line number in logs and exceptions

Michal Liszcz requested to merge github/fork/mliszcz/detect-function-name into main

This PR adds code location information to log messages and origin field in DevFailed exception.

Example log message:

1594734929 [139911612307200] DEBUG dserver/DevTest/test (/home/michal/Documents/cppTango/cppapi/server/subdev_diag.cpp:80) SubDevDiag::set_associated_device() entering ...
1594734929 [139911612307200] DEBUG dserver/DevTest/test (/home/michal/Documents/cppTango/cppapi/server/device_3.cpp:1881) Leaving Device_3Impl::write_attributes_34

Example exception (Except::print_exception output):

30: Tango NamedDevFailedList exception
30:    Exception for object Long64_attr_rw
30:    Index of object in call (starting at 0) = 0
30:        Severity = ERROR
30:        Error reason = DevTest_WriteAttrHardware
30:        Desc : DevFailed from write_attr_hardware
30:        Origin : virtual void DevTest::write_attr_hardware(std::vector<long int>&) at (/home/michal/Documents/cppTango/cpp_test_suite/cpp_test_ds/DevTest.cpp:1244)

The log message is updated automatically if you use macros like ERROR_STREAM or cout5.

To have exception origin field filled automatically, please use TANGO_THROW_EXCEPTION(reason, desc) macro (there is also TANGO_RETHROW_EXCEPTION and corresponding macros for _API_EXCEPTION).

See also: https://github.com/tango-controls/cppTango/pull/564#discussion_r450654487

Edited by Michal Liszcz

Merge request reports