best practices- logging framework with cloud integration

azz-zza
Posts: 45
Joined: Tue Sep 17, 2019 2:58 am

best practices- logging framework with cloud integration

Postby azz-zza » Tue Jul 14, 2020 5:34 am

Hello,
Serial.print with monitoring over usb was a good enough approach with a single prototype.
but with several deployed units, my ability to babysit them over USB/serial is somewhat tasking.

To avoid inventing the wheel, I would appreciate your advise on proper logging framework that can also be leveraged to send log information to a cloud. (I'm thinking about aws iot core with Mqtt)

Thank you in advance.

P.S. it would be nice to have logging to both serial and "cloud" without the need to constantly type 2 statements, checking for connection etc..

AloyseTech
Posts: 22
Joined: Mon Jul 22, 2019 2:29 pm

Re: best practices- logging framework with cloud integration

Postby AloyseTech » Thu Jul 16, 2020 10:43 am

You could use esp_log_set_vprintf to set a custom vprintf function. This function could look like this :

Code: Select all

/*
 * vprintf-like function to replace the logging output method
 */
int dual_vprintf(const char *fmt, va_list ap)
{
    // 1. Log to a custom handler (could be a MQTT queue, UDP socket etc)
    char str[256] = 0;
    snprintf(str, 256, fmt, ap);
    esp_mqtt_client_publish(client, "/topic/log", str, strlen(str), 0, 0);
    
    //2. Still log to the standard output (UART)
    return vprintf(fmt, ap);
}
Note that you would need a task to maintain the mqtt client connection.

azz-zza
Posts: 45
Joined: Tue Sep 17, 2019 2:58 am

Re: best practices- logging framework with cloud integration

Postby azz-zza » Fri Jul 17, 2020 3:20 am

AloyseTech wrote:
Thu Jul 16, 2020 10:43 am
You could use esp_log_set_vprintf to set a custom vprintf function. This function could look like this :

Code: Select all

/*
 * vprintf-like function to replace the logging output method
 */
int dual_vprintf(const char *fmt, va_list ap)
{
    // 1. Log to a custom handler (could be a MQTT queue, UDP socket etc)
    char str[256] = 0;
    snprintf(str, 256, fmt, ap);
    esp_mqtt_client_publish(client, "/topic/log", str, strlen(str), 0, 0);
    
    //2. Still log to the standard output (UART)
    return vprintf(fmt, ap);
}
Note that you would need a task to maintain the mqtt client connection.
agreed, and then i have to figure out some kind of buffer for logs and the log sending progress (over the connection).

Who is online

Users browsing this forum: No registered users and 270 guests