Giter Club home page Giter Club logo

debuglog's Introduction

DebugLog

Logging library for Arduino that can output to both Serial and File with one line

Warning

Dependent libraries removed (>= v0.8.0). If you have already installed this library, please follow:

  • Cloned from GitHub (manually): Please install dependent libraries manually
  • Installed from library manager: re-install this library from library manager
    • Dependent libraries will be installed automatically

Feature

  • Output logs to Serial and File with one line at the same time
  • Output logs with variadic arguments
  • Assertion support (suspend program with messages if assertion fails)
  • Release Mode #define DEBUGLOG_DISABLE_LOG can easily disable logging (LOG_XXXX, ASSERT)
  • Log level control (NONE, ERROR, WARN, INFO, DEBUG, TRACE)
  • Automatically or manually output log to file
  • Multiple file system support (SD, SdFat, SPIFFS, etc.)
  • Support array and container (std::vector, std::deque, std::map) output
  • APIs can also be used in standard C++ apps
  • Log preamble control #define LOG_PREAMBLE exposes customization of string that comes before each log message

Basic Usage

Logging API Comparison

APIs Serial File Log Level Release Mode
LOG_XXXXX YES YES * CONTROLLED DISABLED
ASSERT, ASSERTM YES YES * IGNORED DISABLED
PRINT, PRINTLN YES NO IGNORED ENABLED
PRINT_FILE, PRINTLN_FILE NO YES * IGNORED ENABLED *

* : Only after LOG_FS_ATTACH_AUTO or LOG_FS_ATTACH_MANUAL is called

Simple Log Example

LOG_XXXX output is controlled by log level. Default log level is DebugLogLevel::LVL_INFO

#include <DebugLog.h>

// The default log_leval is DebugLogLevel::LVL_INFO
LOG_ERROR("this is error: log level", 1);
LOG_WARN("this is warn: log level", 2);
LOG_INFO("this is info: log level", 3);
LOG_DEBUG("this is debug: log level", 4);  // won't be printed
LOG_TRACE("this is trace: log level", 5);  // won't be printed

Serial output example

[ERROR] basic.ino L.26 setup : this is error: log level 1
[WARN] basic.ino L.27 setup : this is warn: log level 2
[INFO] basic.ino L.28 setup : this is info: log level 3

Log Level control

By defining DEBUGLOG_DEFAULT_LOG_LEVEL_XXXX, you can change default log level

// You can also set default log level by defining macro (default: INFO)
#define DEBUGLOG_DEFAULT_LOG_LEVEL_TRACE

// Include DebugLog after that
#include <DebugLog.h>

Or you can change log level dynamically by

// You can change log_leval by following macro
LOG_SET_LEVEL(DebugLogLevel::LVL_TRACE);

After setting log level to DebugLogLevel::LVL_TRACE

LOG_ERROR("this is error log");
LOG_WARN("this is warn log");
LOG_INFO("this is info log");
LOG_DEBUG("this is debug log");
LOG_TRACE("this is trace log");

will output

[ERROR] basic.ino L.26 setup : this is error: log level 1
[WARN] basic.ino L.27 setup : this is warn: log level 2
[INFO] basic.ino L.28 setup : this is info: log level 3
[DEBUG] basic.ino L.29 setup : this is debug: log level 4
[TRACE] basic.ino L.30 setup : this is trace: log level 5

Log Preamble Control

The LOG_PREAMBLE macro is called every LOG_XXXX. It defines a string that will be printed between the [LEVEL] and your custom message. To override the default definition, you must define the macro before you #include <DebugLog.h>

Simple LOG_PREAMBLE:

#define LOG_PREAMBLE "||We the People||"
#include <DebugLog.h>

LOG_ERROR("Message 1");
LOG_WARN("Message 2");
LOG_INFO("Message 3");

Serial output

[ERROR] ||We the People|| Message 1
[WARN] ||We the People|| Message 2
[INFO] ||We the People|| Message 3

Default LOG_PREAMBLE:

The Default LOG_PREAMBLE calls other macros and functions. Note the comma separated fields will be space delimeted as they are inputs to the LOG_XXXX(...) macro.

#define LOG_PREAMBLE LOG_SHORT_FILENAME, LOG_MACRO_APPEND_STR(L.__LINE__), __func__, ":"

The LOG_MACRO_APPEND_STR() macro will append a string to the result of a second macro

Assertion

ASSERT suspends program if the provided condition is false

int x = 1;
ASSERT(x != 1); // suspends program here

ASSERTM can also output message in addition to ASSERT

int x = 1;
ASSERTM(x != 1, "It's good to write the reason of fatal error");

PRINT PRINTLN (always output to Serial)

PRINT and PRINTLN is not affected by log level (always visible) and log format

PRINT("DebugLog", "can print variable args: ");
PRINTLN(1, 2.2, "three", "=> like this");

Serial output example

DebugLog can print variable args: 1 2.20 three => like this

Logging to File

Enable File Logger

This preparation is required to use the file logging

// define DEBUGLOG_ENABLE_FILE_LOGGER to enable file logger
#define DEBUGLOG_ENABLE_FILE_LOGGER
#include <DebugLog.h>

Attach to File System

You can log to File automatically by calling this macro. LOG_XXXX and ASSERT are automatically wrote to file depending on the log level

LOG_ATTACH_FS_AUTO(SD, "/log.txt", FILE_WRITE);

Log Leval Control for File Output

By defining DEBUGLOG_DEFAULT_FILE_LEVEL_XXXX, you can change default log level. Default level is DebugLogLevel::LVL_ERROR.

// You can also set default file level by defining macro (default: ERROR)
#define DEBUGLOG_DEFAULT_FILE_LEVEL_INFO

// Include DebugLog after that
#include <DebugLog.h>

Or you can change log level dynamically by

// You can change log_leval by following macro
LOG_FILE_SET_LEVEL(DebugLogLevel::LVL_INFO);

Notes for Auto Logging to File

  • One log function call can takes 3-20 ms if you log to file (depending on environment)
  • There is option to flush to file manually to avoid flushing every log
  • If you've disabled auto saving, you should call LOG_FILE_FLUSH() or LOG_FILE_CLOSE() manually

Flush File Manually

By calling LOG_ATTACH_FS_MANUAL, you can control flush timing manually

LOG_ATTACH_FS_MANUAL(fs, filename, FILE_WRITE);

You should call LOG_FILE_FLUSH() or LOG_FILE_CLOSE() manually to flush to the file

// If LOG_ATTACH_FS_MANUAL is used, you should manually save logs
// however this is much faster than auto save (saving takes few milliseconds)
LOG_FILE_FLUSH(); // manually save to SD card and continue logging
LOG_FILE_CLOSE(); // flush() and finish logging (ASSERT won't be saved to SD)

PRINT_FILE PRINTLN_FILE (always output to File)

PRINT_FILE and PRINTLN_FILE is not affected by log level (always visible) and log format

PRINT_FILE("DebugLog", "can print variable args: ");
PRINTLN_FILE(1, 2.2, "three", "=> like this");

Disable Logging Macro (Release Mode)

You can disable LOG_XXXX and ASSERT macro completely by defining following macro. By disabling log macros, you can save memory usage and cpu overhead (macro receives/calls nothing). Note that PRINT macros are not disabled even in the release mode.

#define DEBUGLOG_DISABLE_LOG

#include <DebugLog.h>

Practical Example

// Uncommenting DEBUGLOG_DISABLE_LOG disables ASSERT and all log (Release Mode)
// PRINT and PRINTLN are always valid even in Release Mode
// #define DEBUGLOG_DISABLE_LOG

// You can also set default log level by defining macro (default: INFO)
// #define DEBUGLOG_DEFAULT_LOG_LEVEL_TRACE

#include <DebugLog.h>

void setup() {
    Serial.begin(115200);
    delay(2000);

    // PRINT and PRINTLN is not affected by log_level (always visible)
    PRINT("DebugLog", "can print variable args: ");
    PRINTLN(1, 2.2, "three", "=> like this");

    // You can change log_leval by following macro
    // LOG_SET_LEVEL(DebugLogLevel::LVL_TRACE);

    // The default log_leval is DebugLogLevel::LVL_INFO
    // 0: NONE, 1: ERROR, 2: WARN, 3: INFO, 4: DEBUG, 5: TRACE
    PRINTLN("current log level is", (int)LOG_GET_LEVEL());

    // The default log_leval is DebugLogLevel::LVL_INFO
    LOG_ERROR("this is error log");
    LOG_WARN("this is warn log");
    LOG_INFO("this is info log");
    LOG_DEBUG("this is debug log");  // won't be printed
    LOG_TRACE("this is trace log");  // won't be printed

    // Log array
    float arr[3] {1.1, 2.2, 3.3};
    PRINTLN("Array can be also printed like this", LOG_AS_ARR(arr, 3));

#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L  // Have libstdc++11
    // Log containers
    std::vector<int> vs {1, 2, 3};
    std::deque<float> ds {1.1, 2.2, 3.3};
    std::map<String, int> ms {{"one", 1}, {"two", 2}, {"three", 3}};
    PRINTLN("Containers can also be printed like", vs, ds, ms);
#endif

    delay(1000);

    // You can also use assert
    // If assertion failed, Serial endlessly prints message
    int x = 1;
    // ASSERT(x != 1);
    // You can also use assert with messages by ASSERTM macro
    ASSERTM(x != 1, "This always fails");
}

Serial Output

DebugLog can print variable args: 1 2.20 three => like this
current log level is 3
[ERROR] basic.ino L.26 setup : this is error log
[WARN] basic.ino L.27 setup : this is warn log
[INFO] basic.ino L.28 setup : this is info log
Array can be also printed like this [1.10, 2.20, 3.30]
Containers can also be printed like [1, 2, 3] [1.10, 2.20, 3.30] {one:1, three:3, two:2}
[ASSERT] basic.ino 51 setup : x != 1 => This always fails

Output Log to both Serial and File

// You can also set default file level by defining macro (default: ERROR)
// #define DEBUGLOG_DEFAULT_FILE_LEVEL_WARN

// if you want to use standard SD library
#include <SD.h>
#define fs SD

// If you want to use SdFat
// #include <SdFat.h>
// SdFat fs;
// SdFatSdio fs;

// If you want use SPIFFS (ESP32) or other FileSystems
// #include <SPIFFS.h>
// #define fs SPIFFS

// after that, include DebugLog.h
#include <DebugLog.h>

void setup() {
    if (fs.begin()) {
        String filename = "log.txt";

        // Set file system to save every log automatically
        LOG_ATTACH_FS_AUTO(fs, filename, FILE_WRITE);

        // Set file system to save log manually
        // LOG_ATTACH_FS_MANUAL(fs, filename, FILE_WRITE);
    }

    // Apart from the log level to be displayed,
    // you can set the log level to be saved to a file (Default is DebugLogLevel::LVL_ERROR)
    // LOG_FILE_SET_LEVEL(DebugLogLevel::LVL_INFO);

    // If LOG_ATTACH_FS_AUTO is used, logs will be automatically saved to SD
    LOG_ERROR("error!");

    // PRINT_FILE and PRINTLN_FILE is not affected by file_level (always visible)
    // PRINT_FILE and PRINTLN_FILE is not displayed to Serial
    PRINT_FILE("DebugLog", "can print variable args: ");
    PRINTLN_FILE(1, 2.2, "three", "=> like this");

    // Apart from the log level to be displayed,
    // you can set the log level to be saved to a file (Default is DebugLogLevel::LVL_ERROR)
    // LOG_FILE_SET_LEVEL(DebugLogLevel::LVL_INFO);

    // The default log_leval is DebugLogLevel::LVL_INFO
    // 0: NONE, 1: ERROR, 2: WARN, 3: INFO, 4: DEBUG, 5: TRACE
    PRINTLN_FILE("current log level is", (int)LOG_FILE_GET_LEVEL());

    // LOG_XXXX outpus both Serial and File based on log_level and file_level
    // The default log_leval is DebugLogLevel::LVL_INFO
    // The default file_leval is DebugLogLevel::LVL_ERROR
    LOG_ERROR("this is error log");  // printed to both Serial and File
    LOG_WARN("this is warn log");    // won't be saved but printed
    LOG_INFO("this is info log");    // won't be saved but printed
    LOG_DEBUG("this is debug log");  // won't be printed
    LOG_TRACE("this is trace log");  // won't be printed

    // Log array
    float arr[3] {1.1, 2.2, 3.3};
    PRINTLN_FILE("Array can be also printed like this", LOG_AS_ARR(arr, 3));

#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L  // Have libstdc++11
    // Log containers
    std::vector<int> vs {1, 2, 3};
    std::deque<float> ds {1.1, 2.2, 3.3};
    std::map<String, int> ms {{"one", 1}, {"two", 2}, {"three", 3}};
    PRINTLN_FILE("Containers can also be printed like", vs, ds, ms);
#endif

    delay(1000);

    // You can also use assert
    // If assertion failed, suspend program after prints message and close files
    int x = 1;
    // ASSERT(x != 1);
    // You can also use assert with messages by ASSERTM macro
    ASSERTM(x != 1, "This always fails");

    // If LOG_ATTACH_FS_MANUAL is used, you should manually save logs
    // however this is much faster than auto save (saving takes few milliseconds)
    // LOG_FILE_FLUSH(); // manually save to SD card and continue logging
    LOG_FILE_CLOSE(); // flush() and finish logging (ASSERT won't be saved to SD)
}

Serial Output

[ERROR] log_to_file.ino L.97 setup : this is error log
[WARN] log_to_file.ino L.98 setup : this is warn log
[INFO] log_to_file.ino L.99 setup : this is info log
[ASSERT] log_to_file.ino 122 setup : x != 1 => This always fails

File Output

DebugLog can print variable args: 1 2.20 three => like this
current log level is 1
[ERROR] log_to_file.ino L.97 setup : this is error log
Array can be also printed like this [1.10, 2.20, 3.30]
Containers can also be printed like [1, 2, 3] [1.10, 2.20, 3.30] {one:1, three:3, two:2}
[ASSERT] log_to_file.ino 122 setup : x != 1 => This always fails

Control Log Level Scope

You can control the scope of DebugLog by including following header files.

  • DebugLogEnable.h
  • DebugLogDisable.h
  • DebugLogRestoreState.h

After including DebugLogEnable.h or DebugLogDisable.h, macros are enabled/disabled. Finally you should include DebugLogRestoreState.h to restore the previous state. Please see practical example examples/control_scope for details.

#define DEBUGLOG_DISABLE_LOG
#include <DebugLog.h>

// here is release mode (disable DebugLog)

#include <DebugLogEnable.h>

// here is debug mode (enable DebugLog)

#include <DebugLogRestoreState.h>

// here is release mode (restored)

Logging APIs for both Serial and File

Both Serial and File

These logging APIs are enabled only if log level is control the visibility.

#define LOG_ERROR(...)
#define LOG_WARN(...)
#define LOG_INFO(...)
#define LOG_DEBUG(...)
#define LOG_TRACE(...)

Assertion suspends program if the condition is true.

#define ASSERT(b)
#define ASSERTM(b, msg)

Log only to Serial

PRINT and PRINTLN are available in both release and debug mode.

#define PRINT(...)
#define PRINTLN(...)

Log only to File

PRINT_FILE and PRINTLN_FILE are available in both release and debug mode.

#define PRINT_FILE(...)
#define PRINTLN_FILE(...)

If you use LOG_ATTACH_FS_MANUAL, these macros are used to flush files manually.

// Arduino Only (Manual operation)
#define LOG_FILE_FLUSH()
#define LOG_FILE_CLOSE()

Log Options

Log Option APIs

#define LOG_AS_ARR(arr, size)
#define LOG_GET_LEVEL()
#define LOG_SET_LEVEL(level)
#define LOG_SET_OPTION(file, line, func)
#define LOG_SET_DELIMITER(delim)
#define LOG_SET_BASE_RESET(b)
// Arduino Only
#define LOG_ATTACH_SERIAL(serial)
#define LOG_FILE_IS_OPEN()
#define LOG_FILE_GET_LEVEL()
#define LOG_FILE_SET_LEVEL(lvl)
#define LOG_ATTACH_FS_AUTO(fs, path, mode)
#define LOG_ATTACH_FS_MANUAL(fs, path, mode)

Log Level

enum class DebugLogLevel {
    NONE  = 0,
    ERROR = 1,
    WARN  = 2,
    INFO  = 3,
    DEBUG = 4,
    TRACE = 5
};

Log Base

enum class DebugLogBase {
    DEC = 10,
    HEX = 16,
    OCT = 8,
    BIN = 2,  // only for Arduino
};

Log Precision

enum class LogPrecision {
    ZERO,
    ONE,
    TWO,
    THREE,
    FOUR,
    FIVE,
    SIX,
    SEVEN,
    EIGHT,
};

Dependent Libraries

Used Inside of

License

MIT

debuglog's People

Contributors

erezbinyamin avatar hideakitai avatar tpanajott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

debuglog's Issues

LogPrecision does not name a type

Hello,

I am trying to compile a small C++ program for testing hideakitai/MsgPack. However, I get the following error:

DebugLog/DebugLog.h:22:39: error: ‘LogPrecision’ in namespace ‘arx::debug’ does not name a type
   22 | using DebugLogPrecision = arx::debug::LogPrecision;
      |                                       ^~~~~~~~~~~~

LogPrecision is used here:

using DebugLogPrecision = arx::debug::LogPrecision;

But if ARDUINO is not defined, LogPrecision is not available:

#ifdef ARDUINO
enum class LogPrecision {
ZERO,
ONE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
};
#endif

I suggest replacing line 22 with:

#ifdef ARDUINO
using DebugLogPrecision = arx::debug::LogPrecision;
#endif

DebugLog.cpp

//to avoid multiple declaration issue

#include <DebugLog.h>

namespace arx {
namespace debug {

#ifdef ARDUINO
  Stream* stream {&Serial};
#endif

#ifdef ARDUINO      
Logger* logger {nullptr};
bool b_auto_save {false};
bool b_only_sd {false};
LogLevel log_level = LogLevel::VERBOSE;

#endif
}

}

and extern these variables in .h file

ESP8266 problem

Hello,
I try your library, is awsome, but I have trouble to run it on ESP8266 (D1 mini V2). I use PlatformIO. When I comment or change second LOG to PRINT it work with no error. I am confused. This code do exception (on ESP32 it work with no problem).
main.cpp:

#include <DebugLog.h>

void setup() {
    Serial.begin(115200);
    delay(2000);
    LOG_SET_LEVEL(DebugLogLevel::LVL_TRACE);
    LOG_DEBUG("Program start");
}

void loop() {
    LOG_ERROR("Main");
}

Exception:

Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4023b017 depc=0x00000000

LoadStoreError: Processor internal physical address or data error during load or store
  excvaddr=0x4023b017 in etharp_output at ??:?

>>>stack>>>

ctx: cont
sp: 3ffffd70 end: 3fffffc0 offset: 0190
3fffff00:  00000007 00000001 3fffff3c 4020197c
3fffff10:  00000000 4023b017 3fffff3c 402019b5
3fffff20:  00000007 3ffee510 3fffff90 4020123f
3fffff30:  00000000 3ffee500 00000000 00000020
3fffff40:  7070632e 01000000 00000000 3ffee500
3fffff50:  00000000 00000000 3ffee518 00000000
3fffff60:  4023b017 3ffe88ce 3ffee518 402019b5
3fffff70:  40202519 00000000 3ffee510 3ffee5c4  
3fffff80:  3fffdad0 00000000 3ffee510 4020138c
3fffff90:  3ffef384 0015001f 88000000 feefeffe
3fffffa0:  feefeffe feefeffe 3ffee5b0 40201f84
3fffffb0:  feefeffe feefeffe 3ffe85d8 40100c25
<<<stack<<<

0x4020197c in String::copy(char const*, unsigned int) at ??:?
0x4023b017 in etharp_output at ??:?
0x402019b5 in String::String(char const*) at ??:?
0x4020123f in arx::debug::Manager::generate_header(arx::debug::LogLevel, char const*, int, char const*) const at ??:?
0x4023b017 in etharp_output at ??:?
0x402019b5 in String::String(char const*) at ??:?
0x40202519 in __delay at ??:?
0x4020138c in setup at ??:?
0x40201f84 in loop_wrapper() at core_esp8266_main.cpp:?
0x40100c25 in cont_wrapper at ??:?

Second decoder (Arduino IDE):

Exception 3: LoadStoreError: Processor internal physical address or data error during load or store
PC: 0x4000bf64
EXCVADDR: 0x4023b007

Decoding stack results
0x40201970: String::copy(char const*, unsigned int) at C:\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\WString.cpp line 225
0x402019a9: String::String(char const*) at C:\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\WString.cpp line 41
0x4020123b: arx::debug::Manager::generate_header(arx::debug::LogLevel, char const*, int, char const*) const at C:\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/WString.h line 373
0x402019a9: String::String(char const*) at C:\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\WString.cpp line 41
0x40202505: __delay(unsigned long) at C:\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_wiring.cpp line 55
0x4020138a: setup() at C:\\Documents\Arduino\libraries\DebugLog/DebugLog/Manager.h line 121
0x40201f70: loop_wrapper() at C:\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_main.cpp line 198

PlatformIo.ini:

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
monitor_speed = 115200
monitor_filters = esp8266_exception_decoder
lib_deps = 
    hideakitai/DebugLog

[QUESTION/FEATURE REQUEST] Cutsom log format - add timestamp

Is it possible to add a custom log format? Specifically I'm wanting to prefix each log with a timestamp, either millis() or YYMMDDHHMMSS if RTC is available.

Instead of implementing the time handling internally, probably best bet is a custom format callback or something?

Does anything like this exists?

If not would you be interested in PR? If so any suggestion on best place to implement?

LOG_ERROR' was not declared in this scope

hello ,i just tried your librarie but there is an error in your example
tested with ESP8266 wemos D1 mini

G:\Documents\Arduino\libraries\Debug\example\example.ino: In function 'void setup()':
example:11:32: error: 'LOG_ERROR' was not declared in this scope
   LOG_ERROR("this is error log");
                                ^
example:12:36: error: 'LOG_WARNING' was not declared in this scope
   LOG_WARNING("this is warning log");
                                    ^
example:13:36: error: 'LOG_VERBOSE' was not declared in this scope
   LOG_VERBOSE("this is verbose log");
                                    ^
example:15:17: error: 'Debug' has not been declared
   LOG_SET_LEVEL(Debug::LogLevel::WARNING);
                 ^
example:15:41: error: 'LOG_SET_LEVEL' was not declared in this scope
   LOG_SET_LEVEL(Debug::LogLevel::WARNING);
                                         ^
example:22:17: error: 'Debug' has not been declared
   LOG_SET_LEVEL(Debug::LogLevel::ERROR);
                 ^
example:29:17: error: 'Debug' has not been declared
   LOG_SET_LEVEL(Debug::LogLevel::NONE);
                 ^
example:39:16: error: 'ASSERT' was not declared in this scope
   ASSERT(x != 1); // if assertion failed, Serial endlessly prints message
                ^
exit status 1
'LOG_ERROR' was not declared in this scope

Esp32-s3 compilation error, with a certain #include order

Platformio,
[env:esp32-s3-devkitc-1] platform = espressif32 board = esp32-s3-devkitc-1 framework = arduino monitor_speed = 115200 build_flags = -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1

`Processing esp32-s3-devkitc-1 (platform: espressif32; board: esp32-s3-devkitc-1; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s3-devkitc-1.html
PLATFORM: Espressif 32 (6.1.0) > Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 @ 3.20007.0 (2.0.7)
  • tool-esptoolpy @ 1.40500.0 (4.5.0)
  • toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
  • toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 39 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- ESPAsyncWebServer-esphome @ 3.0.0
    |-- MsgPack @ 0.3.19
    |-- SPI @ 2.0.0
    |-- TFT_eSPI @ 2.5.31
    Building in release mode
    Compiling .pio/build/esp32-s3-devkitc-1/src/main.cpp.o
    In file included from src/main.cpp:3:
    .pio/libdeps/esp32-s3-devkitc-1/TFT_eSPI/TFT_eSPI.h:975:8: warning: #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available! [-Wcpp]
    #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!
    ^~~~~~~
    In file included from .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack/util/DebugLog/DebugLog.h:17,
    from .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack.h:5,
    from src/main.cpp:5:
    .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack/util/DebugLog/DebugLog/Manager.h: In member function 'void arx::debug::Manager::attach(FsType&, const String&, const FileMode&, bool)':
    .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack/util/DebugLog/DebugLog/Manager.h:76:47: error: 'File' was not declared in this scope
    logger = new FsFileLogger<FsType, File>(s, path, mode);
    ^~~~
    .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack/util/DebugLog/DebugLog/Manager.h:76:47: note: suggested alternative:
    In file included from .pio/libdeps/esp32-s3-devkitc-1/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h:152,
    from .pio/libdeps/esp32-s3-devkitc-1/TFT_eSPI/TFT_eSPI.h:96,
    from src/main.cpp:3:
    /home/andriy/.platformio/packages/framework-arduinoespressif32/libraries/FS/src/FS.h:47:7: note: 'fs::File'
    class File : public Stream
    ^~~~
    In file included from .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack/util/DebugLog/DebugLog.h:17,
    from .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack.h:5,
    from src/main.cpp:5:
    .pio/libdeps/esp32-s3-devkitc-1/MsgPack/MsgPack/util/DebugLog/DebugLog/Manager.h:76:51: error: template argument 2 is invalid
    logger = new FsFileLogger<FsType, File>(s, path, mode);
    ^
    *** [.pio/build/esp32-s3-devkitc-1/src/main.cpp.o] Error 1`

`#include "Arduino.h"
#include <SPI.h>
#include <TFT_eSPI.h>
#include <ESPAsyncWebServer.h>
#include <MsgPack.h>

void setup() {
}

void loop() {

}`

Reduce code footprint when log level is decreased.

#define LOG_ERROR(...) DebugLog::Manager::get().log(arx::debug::LogLevel::LVL_ERROR, LOG_PREAMBLE, __VA_ARGS__)

TLDR;

It'd be nice if using less verbose logging actually build a smaller binary.

Explanation

In the current state if the log level is set to ERROR then only LOG_ERROR messages will be printed, but all of the other code for the other log messages will still be executed. It just will eventually not print when the log function is called. Macros like #ifdef could be used to exculde unused LOG_XXXX messages.

The change would be to simply add some code to DebugLogEnable.h

#if defined(DEBUGLOG_DEFAULT_LOG_LEVEL_ERROR)
  #define LOG_WARN(...)
  #define LOG_INFO(...)
  #define LOG_DEBUG(...)
  #define LOG_TRACE(...)
#elif defined(DEBUGLOG_DEFAULT_LOG_LEVEL_WARN)
  #define LOG_INFO(...)
  #define LOG_DEBUG(...)
  #define LOG_TRACE(...)
#elif defined(DEBUGLOG_DEFAULT_LOG_LEVEL_INFO)
  #define LOG_DEBUG(...)
  #define LOG_TRACE(...)
#elif defined(DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG)
  #define LOG_TRACE(...)
#endif

how to format floating point values

I am a noob in C++ and have a question regarding logging floats with DebugLog.
The floats are always in a format with 2 decimals but i need up to 6 decimals.
Is there a ways to change the format of the output of floats?

LOG_ATTACH_FS_AUTO with SD-Card do not work

When i use the example with an SD-Card the LOG_ATTACH_FS_AUTO() creates a file with size equal to available bytes left on SD-Card.
the content of the file seems to be random.

Version 0.6.0.

When using Verion 0.5.1 (and different interface ) it works fine.

Strange behavior log in two serial data ports events

When a log is output from two serial data ports events, the data is mixed and partially discarded.
Example log
2020-10-15 12:56:57.250|VERBOSE|CommandProcessor.cpp|65|Execute|cmd:T02020-10-15 12:56:57.256|VERBOSE|TATransport.cpp|250|RetranslatePSCommand|Enter

The expected log
2020-10-15 12:56:57.250|VERBOSE|TATransport.cpp|171|SeparatePCCommands|Enter
2020-10-15 12:56:57.256|VERBOSE|CommandProcessor.cpp|65|Execute|cmd:T01,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.