Skip to content

Commit

Permalink
logging - possibility to set log level as -D
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Jul 29, 2020
1 parent 0cad580 commit 99bc49a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/utility/EspAtDrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const char QOUT_COMMA_QOUT[] PROGMEM = "\",\"";
const char PROCESSED[] PROGMEM = " ...processed";
const char IGNORED[] PROGMEM = " ...ignored";

#if LOG_LEVEL >= LOG_LEVEL_DEBUG
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_DEBUG
class DebugPrint : public Print {
public:
Print* stream;
Expand All @@ -63,7 +63,7 @@ class DebugPrint : public Print {

bool EspAtDrvClass::init(Stream* _serial, int8_t resetPin) {
serial = _serial;
#if LOG_LEVEL < LOG_LEVEL_DEBUG
#if WIFIESPAT_LOG_LEVEL < LOG_LEVEL_DEBUG
cmd = _serial;
#else
debugPrint.stream = serial;
Expand Down
8 changes: 4 additions & 4 deletions src/utility/EspAtDrvLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
#include "EspAtDrvLogging.h"
#include <Arduino.h> // to include PROGMEM in a compatible way

#if LOG_LEVEL >= LOG_LEVEL_ERROR
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_ERROR
const char LOG_ERROR_PREFIX_PROGMEM[] PROGMEM = LOG_ERROR_PREFIX;
#endif
#if LOG_LEVEL >= LOG_LEVEL_WARN
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_WARN
const char LOG_WARN_PREFIX_PROGMEM[] PROGMEM = LOG_WARN_PREFIX;
#endif
#if LOG_LEVEL >= LOG_LEVEL_INFO
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_INFO
const char LOG_INFO_PREFIX_PROGMEM[] PROGMEM = LOG_INFO_PREFIX;
#endif
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_DEBUG
const char LOG_DEBUG_PREFIX_PROGMEM[] PROGMEM = LOG_DEBUG_PREFIX;
#endif
14 changes: 9 additions & 5 deletions src/utility/EspAtDrvLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef _WIFIESPAT_DEBUG_H_
#define _WIFIESPAT_DEBUG_H_

#include <Arduino.h>

#define FSH_P const __FlashStringHelper*

#define LOG_LEVEL_SILENT 0
Expand All @@ -28,7 +30,9 @@
#define LOG_LEVEL_INFO 3
#define LOG_LEVEL_DEBUG 4

#define LOG_LEVEL LOG_LEVEL_SILENT
#ifndef WIFIESPAT_LOG_LEVEL
#define WIFIESPAT_LOG_LEVEL LOG_LEVEL_SILENT
#endif

#ifdef ARDUINO_SAM_ZERO // M0
#define LOG_OUTPUT SerialUSB
Expand All @@ -37,7 +41,7 @@
#endif

#define LOG_ERROR_PREFIX "esp ERROR: "
#if LOG_LEVEL >= LOG_LEVEL_ERROR
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_ERROR
extern const char LOG_ERROR_PREFIX_PROGMEM[];
#define LOG_ERROR_PRINT_PREFIX() LOG_OUTPUT.print((FSH_P) LOG_ERROR_PREFIX_PROGMEM)
#define LOG_ERROR_PRINT(msg) LOG_OUTPUT.print(msg)
Expand All @@ -49,7 +53,7 @@ extern const char LOG_ERROR_PREFIX_PROGMEM[];
#endif

#define LOG_WARN_PREFIX "esp WARN: "
#if LOG_LEVEL >= LOG_LEVEL_WARN
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_WARN
extern const char LOG_WARN_PREFIX_PROGMEM[];
#define LOG_WARN_PRINT_PREFIX() LOG_OUTPUT.print((FSH_P) LOG_WARN_PREFIX_PROGMEM)
#define LOG_WARN_PRINT(msg) LOG_OUTPUT.print(msg)
Expand All @@ -61,7 +65,7 @@ extern const char LOG_WARN_PREFIX_PROGMEM[];
#endif

#define LOG_INFO_PREFIX "esp INFO: "
#if LOG_LEVEL >= LOG_LEVEL_INFO
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_INFO
extern const char LOG_INFO_PREFIX_PROGMEM[];
#define LOG_INFO_PRINT_PREFIX() LOG_OUTPUT.print((FSH_P) LOG_INFO_PREFIX_PROGMEM)
#define LOG_INFO_PRINT(msg) LOG_OUTPUT.print(msg)
Expand All @@ -73,7 +77,7 @@ extern const char LOG_INFO_PREFIX_PROGMEM[];
#endif

#define LOG_DEBUG_PREFIX "esp> "
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
#if WIFIESPAT_LOG_LEVEL >= LOG_LEVEL_DEBUG
extern const char LOG_DEBUG_PREFIX_PROGMEM[];
#define LOG_DEBUG_PRINT_PREFIX() LOG_OUTPUT.print((FSH_P) LOG_DEBUG_PREFIX_PROGMEM)
#define LOG_DEBUG_PRINT(msg) LOG_OUTPUT.print(msg)
Expand Down

0 comments on commit 99bc49a

Please sign in to comment.