-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional attributes for log messages #1026
Conversation
From the original PR:
We have multiple options here, starting with the similar named parameters syntax implemented via overloaded Log.info(Log.attributes().setCode(-1).setDetails("details"), "message"); I'm kind of ambivalent about adding such functionality though. Most of the attributes are automatic and cannot be extended easily by user. As for the |
Ok, we could make it a parameter, which get's a bit confusing with nesting...how about using a more fluid style of coding?
So the attributes class for a log subsumes the logger and exposes the same interface. |
Looks good 👍 |
Added user API with the following syntax: Log.code(-1).details("details").info("message"); |
|
||
```cpp | ||
// EXAMPLE | ||
Log("This is %s message", "info"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the "info" parameter in case someone confuses it with actually setting the logging level. Something like
Log("The secret of everything is %d", 42);
If the |
There's no other way to forward C-style Also, |
I think this should be ready for merging, @m-mcgowan? I've moved the formatting code in question to the |
Github doesn't allow to change base branch for existing PRs, so I'm recreating #1022 after base branch of the latter PR has been merged to
develop
.This PR is rebased on top of current
develop
.Original message:
This PR implements
LOG_ATTR()
macro which allows to specify additional attributes for log messages. For example:Only
code
anddetail
attributes are supported at the moment. New attributes (e.g. thread ID), can be easily added by extendingLogAttributes
structure.The implementation involves a bit of preprocessor magic in order to support named parameters syntax in both C and C++, so this patch also adds small header file with some typical preprocessor primitives (see
services/inc/preprocessor.h
). In principle, the same could be easily implemented using Boost.Preprocessor, I just wasn't sure if we want to introduce additional compile-time dependency for the firmware build.Note that this patch is based on the
feature/logger_api
branch and introduces ABI breaking changes to the existent dynalib interface of the logging library. It is likely too late to include this patch into upcoming 0.6.0, so I would mark current logging API as "experimental and subject to change" in thedevelop
and postpone publishing of the logging API reference until next release.Doneness: