dlt-daemon icon indicating copy to clipboard operation
dlt-daemon copied to clipboard

Declare and register multiple context not working

Open ahmedwahdan opened this issue 3 years ago • 5 comments

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 avatar Aug 08 '22 11:08 ahmedwahdan

@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 avatar Aug 10 '22 08:08 thanhbnq

@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 avatar Aug 10 '22 09:08 ahmedwahdan

@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 avatar Aug 10 '22 10:08 thanhbnq

@thanhbnq code updated

ahmedwahdan avatar Aug 10 '22 11:08 ahmedwahdan

@ahmedwahdan Thanks for your updates. I would like to share some points based on the samples:

  1. 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.

  2. In your application code, at runtime, we should firstly check whether the registration of context happens. dlt-control -o -u and check content of file dlt-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 )

thanhbnq avatar Aug 11 '22 06:08 thanhbnq

Hello @ahmedwahdan , Do you have any updates on this issue?

thanhbnq avatar Sep 28 '22 08:09 thanhbnq