Impletement print-like function using NRF_LOG

I need to define a function to print message and register to other module. In my application, NRF_LOG is used by most modules so I need to use NRF_LOG to construct this printf-like function. 

Belowed is code:

int mylog(const char *format, ...)
{
    NRF_LOG_RAW_INFO("%s (%d%s: ""I", __LINE__, "MyPrintf");
    NRF_LOG_RAW_INFO(format);
    NRF_LOG_RAW_INFO("\n");
    return 0;
}
Some code to test it:
mylog("My printf success!"); It print well;
mylog("My printf success with num%d!", 50); num doesn't equal to 50, something went wrong.
Anyone know how to achieve this? 
Thank you!
Young
Parents Reply
  • typedef int (*secure_log)(const char *format, ...);
    
    struct secure_port_apis_t
    {
        secure_log log;
    };
    int secure_port_apis_reg(const struct secure_port_apis_t *apis);

    See code above. 

    Call secure_port_apis_reg() to register APIs. So define log function below:

    int sec_log(const char *format, ...)
    {
        NRF_LOG_RAW_INFO(format);
        NRF_LOG_RAW_INFO("\n");
        return 0;
    }

    It does't work well.

Children
Related