Declare and register multiple context not working
My service is divided into multiple classes and instead of defining all contexts in main and import them in deafferent classes, I declare the context in class and register it in init function.
Some the logs are not showing, not sure of the reason!
@ahmedwahdan Thanks for your question. From your description, it is quite difficult for us to support you. It would be really helpful if you could share some sample codes.
@thanhbnq Thanks for your follow up
namespace test
{
namespace
{
DLT_DECLARE_CONTEXT(client_context);
static constexpr char DLT_CONTEXT[] = "Test2";
static constexpr char DLT_CONTEXT_DESCRIPTION[] = "test2";
} // anonymous namespace
bool MyClass::init(const std::string& _app_name)
{
DLT_REGISTER_CONTEXT(client_context, DLT_CONTEXT, DLT_CONTEXT_DESCRIPTION);
DLT_LOG(client_context, DLT_LOG_INFO, DLT_STRING("initializing client ..."));
}
}
-------------------------------------------------------
namespace
{
constexpr char DLT_APP_NAME[]{"Test"};
constexpr char DLT_APP_DESCRIPTION[]{"Test"};
DLT_DECLARE_CONTEXT(main_context)
} // namespace
int main()
{
// register application for DLT logging
DLT_REGISTER_APP(DLT_APP_NAME, DLT_APP_DESCRIPTION);
DLT_REGISTER_CONTEXT(main_context, "main", "main context.");
DLT_ENABLE_LOCAL_PRINT();
DLT_LOG(main_context, DLT_LOG_DEBUG, DLT_STRING("Creating instance"));
test::MyClass obj;
obj.init();
// starting background services
}
@ahmedwahdan
DLT_REGISTER_CONTEXT(client_context, DLT_CONTEXT, DLT_CONTEXT_DESCRIPTION);
It looks like the definition of "DLT_CONTEXT" is missing in your sample.
@thanhbnq code updated
@ahmedwahdan Thanks for your updates. I would like to share some points based on the samples:
-
Please be aware of the max length of IDs (App ID and Context ID) is 4. Based on your sample, the context ID "Test2" is somehow having 4 first bytes same as the main context => then it could be an unexpected double registration context here. I believe it won't be the case in your application code but it is also worthy of notice.
-
In your application code, at runtime, we should firstly check whether the registration of context happens.
dlt-control -o -uand check content of filedlt-runtime-context.cfg(this file will be located in the directory https://github.com/COVESA/dlt-daemon/blob/master/doc/dlt.conf.5.md#persistancestoragepath )
Hello @ahmedwahdan , Do you have any updates on this issue?