Skip to content

Commit

Permalink
Implement ESP_LOGx override option
Browse files Browse the repository at this point in the history
Usable for library developers who write code not dependent on Arduino.
Adding 3 lines to the includes will permit their debug messages to be
visible in Arduino IDE or when enabled under IDF
  • Loading branch information
me-no-dev committed Oct 13, 2017
1 parent c8ffcac commit 409c75d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Kconfig
Expand Up @@ -66,6 +66,16 @@ config ARDUHAL_LOG_COLORS
Enable ANSI terminal color codes in bootloader output.
In order to view these, your terminal program must support ANSI color codes.

config ARDUHAL_ESP_LOG
bool "Forward ESP_LOGx to Arduino log output"
default "n"
help
This option will redefine the ESP_LOGx macros to Arduino's log_x macros.
To enable for your application, add the follwing after your includes:
#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif

endmenu

config AUTOCONNECT_WIFI
Expand Down
16 changes: 16 additions & 0 deletions cores/esp32/esp32-hal-log.h
Expand Up @@ -107,6 +107,22 @@ int log_printf(const char *fmt, ...);
#define log_e(format, ...)
#endif

#ifdef CONFIG_ARDUHAL_ESP_LOG
#include "esp_log.h"

#undef ESP_LOGE
#undef ESP_LOGW
#undef ESP_LOGI
#undef ESP_LOGD
#undef ESP_LOGV

#define ESP_LOGE(tag, ...) log_e(__VA_ARGS__)
#define ESP_LOGW(tag, ...) log_w(__VA_ARGS__)
#define ESP_LOGI(tag, ...) log_i(__VA_ARGS__)
#define ESP_LOGD(tag, ...) log_d(__VA_ARGS__)
#define ESP_LOGV(tag, ...) log_v(__VA_ARGS__)

This comment has been minimized.

Copy link
@ankostis

ankostis Mar 31, 2022

Contributor

Isn't the tag argument discarded, thus?

#endif

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 13 additions & 0 deletions docs/esp-idf_component.md
@@ -1,6 +1,8 @@
To use as a component of ESP-IDF
=================================================

## Installation

- Download and install [esp-idf](https://github.com/espressif/esp-idf)
- Create blank idf project (from one of the examples)
- in the project folder, create a folder called components and clone this repository inside
Expand Down Expand Up @@ -55,3 +57,14 @@ To use as a component of ESP-IDF
- If enabled, WiFi will start with the last known configuration
- Else it will wait for WiFi.begin
- ```make flash monitor``` will build, upload and open serial monitor to your board

## Logging To Serial

If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines after your includes:

```cpp
#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif
```

1 change: 1 addition & 0 deletions tools/sdk/include/config/sdkconfig.h
Expand Up @@ -134,6 +134,7 @@
#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32
#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1
#define CONFIG_ARDUHAL_ESP_LOG 1
#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240
#define CONFIG_MBEDTLS_HARDWARE_AES 1
Expand Down
1 change: 1 addition & 0 deletions tools/sdk/sdkconfig
Expand Up @@ -126,6 +126,7 @@ CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_DEBUG=
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE=
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=1
CONFIG_ARDUHAL_LOG_COLORS=
CONFIG_ARDUHAL_ESP_LOG=y
CONFIG_AUTOCONNECT_WIFI=
CONFIG_AWS_IOT_SDK=
CONFIG_BT_ENABLED=y
Expand Down

5 comments on commit 409c75d

@cyberman54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using PlatformIO as IDE developing for platform esp32 on framework arduino.
I included

esp32-hal-log.h

but i still see only log message of type error.
The test code below shows only the log message "Error", no one from the others.

#include <Arduino.h>
#include "esp32-hal-log.h"

void setup() {
    Serial.begin(115200); 
    esp_log_level_set("*", ESP_LOG_VERBOSE);  
    ESP_LOGE("TAG", "Error");
    ESP_LOGW("TAG", "Warning");
    ESP_LOGI("TAG", "Info");
    ESP_LOGD("TAG", "Debug");
    ESP_LOGV("TAG", "Verbose");
}

void loop() {
}

results to:
[E][main.cpp:16] setup(): Error

@stickbreaker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyberman54 when you compiled your code, what did you set the log level to? Set your logging level to Verbose.

Chuck.

@cyberman54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using a

#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE

and a build option
-DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE

Both show no impact, i still get only Logs of type error.

This makes debugging difficult... :-(
Any suggestions how to solve this?

@beegee-tokyo
Copy link
Contributor

@beegee-tokyo beegee-tokyo commented on 409c75d Jan 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the Wiki ;) enable log levels

@cyberman54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the crucial hint, thank you very much!

Setting

build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG

solved my problem.

Please sign in to comment.