Use the right values for CODE_LINE and CODE_FUNC in journal traces

George Liu liuxiwei1013 at gmail.com
Tue May 11 16:03:19 AEST 2021


Hey everyone:

I have a question:
When we track the CODE_LINE and CODE_FUNC values in the journal, the
CODE_LINE and CODE_FUNC attribute values are displayed incorrectly.
issue link: https://github.com/openbmc/openbmc/issues/2297

Today, OpenBMC has supported C++20, and has included
`experimental/source_location` in C++20, which can flexibly obtain the
CODE_LINE and CODE_FUNC attribute values.
The following is an example:

```
void log(const std::string_view& message, const
std::experimental::source_location& location =
std::experimental::source_location::current())
{
    std::cout << "info:" << location.file_name() << ":" <<
location.line() << " " << message << '\n';
}

int main()
{
    log("Hello world!");
}
```
link: https://en.cppreference.com/w/cpp/utility/source_location

So my initial idea is to define `const
std::experimental::source_location& location =
std::experimental::source_location::current()` into the log method.
But for the log method, has defined a variable parameter, so it can
not receive a default parameter again.
link: https://github.com/openbmc/phosphor-logging/blob/master/phosphor-logging/log.hpp#L157

Does everyone have a better way to process it? Please let me know and
we can discuss it here.

Thanks a lot.

George Liu


More information about the openbmc mailing list