Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Support log redirection #9814

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

Closed
1 task done
yaqwsx opened this issue Jun 9, 2024 · 11 comments
Closed
1 task done

Support log redirection #9814

yaqwsx opened this issue Jun 9, 2024 · 11 comments
Labels
Type: Feature request Feature request for Arduino ESP32

Comments

@yaqwsx
Copy link

yaqwsx commented Jun 9, 2024

Related area

Core of the framework

Hardware specification

Not relevant

Is your feature request related to a problem?

The logging facilities provided by the Arduino framework are hard-coded to the main serial output. This is often unwanted (e.g. when the persistence of logs is required or the serial interface needs to be free for other purposes).

Describe the solution you'd like

Allow the user to specify a custom sink function for the logs.

Describe alternatives you've considered

I wanted to use the built-in ESP-IDF logging facilities; however, I ran into #9813

Additional context

No response

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.
@yaqwsx yaqwsx added the Type: Feature request Feature request for Arduino ESP32 label Jun 9, 2024
@me-no-dev
Copy link
Member

me-no-dev commented Jun 10, 2024

#include "rom/ets_sys.h"

static void custom_debug_write_char(char c) {
  //send the char to wherever you want, but be aware that this code might be called from interrupt
}

ets_install_putc1((void (*)(char)) & custom_debug_write_char);
ets_install_putc2(NULL);

@VojtechBartoska VojtechBartoska added the Resolution: Awaiting response Waiting for response of author label Jun 12, 2024
@yaqwsx
Copy link
Author

yaqwsx commented Jun 12, 2024

Thank you for the proposed solution. However, I am afraid of unwanted consequences of the proposed solution - it doesn't redirect the output of logging, but the output of the underlying layer. Thus any code using the ets_ function for output will be affected.

A quick grep of the Arduino framework showed that ets_printf isn't used extensively (just to output the reboot message), however, I have already seen 3rd party out in the wild using it. Thus, I don't find the proposed solution to be exactly clean. On top of that, if there was an interface to supply custom log_v and isr_log_v functions, the logging facility could store the format string and arguments separately (e.g., to save bandwidth or storage). This is not possible in the proposed solution. On top of that, we can't supply separate function to handle isr and non-isr context in you proposed solution.

@everslick
Copy link
Contributor

esp_log_set_vprintf(...); in combination of setting -DUSE_ESP_IDF_LOG -DTAG=\"CORE\" in CFLAGS works for most of the logs for me.

@igrr
Copy link
Member

igrr commented Jun 14, 2024

logging facility could store the format string and arguments separately (e.g., to save bandwidth or storage). This is not possible in the proposed solution. On top of that, we can't supply separate function to handle isr and non-isr context in you proposed solution

The new logging library is in development in ESP-IDF and it should address both points. I think the initial version will appear in ESP-IDF before the end of the year.

@yaqwsx
Copy link
Author

yaqwsx commented Jun 14, 2024

@igrr: Thank you for the update. Nevertheless, if I understood correctly, the Arduino framework is opinionated, hence they reimplement logging (differently than ESP-IDF). Will this change also propagate to the Arduino framework?

@Parsaabasi
Copy link

Hello,

Due to the overwhelming volume of issues currently being addressed, we have decided to close the previously received tickets. If you still require assistance or if the issue persists, please don't hesitate to reopen the ticket.

Thanks.

@yaqwsx
Copy link
Author

yaqwsx commented Jan 15, 2025

The issue persists, however, it seems that I don't have permission to reopen, I can only comment.

@Muskanjhawar
Copy link

esp_log_set_vprintf(...); in combination of setting -DUSE_ESP_IDF_LOG -DTAG=\"CORE\" in CFLAGS works for most of the logs for me

where should i add this -DUSE_ESP_IDF_LOG -DTAG=\"CORE\" ??

@kaerbr
Copy link

kaerbr commented Mar 9, 2025

@Muskanjhawar in the platformio.ini
build_flags = -DUSE_ESP_IDF_LOG -DTAG=\"CORE\"

@Muskanjhawar
Copy link

Muskanjhawar commented Mar 10, 2025 via email

@Jason2866
Copy link
Collaborator

Moving to discussions since it is integrated and possible to use.

@Jason2866 Jason2866 converted this issue into discussion #11117 Mar 13, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Type: Feature request Feature request for Arduino ESP32
Projects
Development

No branches or pull requests

10 participants