feat: Add central logging pragma#843
Conversation
|
Very Nice! |
I did my best to assign LOG_ERR where I found them appropriate, but I am sure I missed quite a lot |
|
| [env:gh_release] | ||
| extends = base | ||
| build_flags = | ||
| ${base.build_flags} | ||
| -DCROSSPOINT_VERSION=\"${crosspoint.version}\" | ||
| -DENABLE_SERIAL_LOG | ||
| -DLOG_LEVEL=0 ; Set log level to error for release builds | ||
|
|
||
| [env:gh_release_rc] | ||
| extends = base | ||
| build_flags = | ||
| ${base.build_flags} | ||
| -DCROSSPOINT_VERSION=\"${crosspoint.version}-rc+${sysenv.CROSSPOINT_RC_HASH}\" | ||
| -DENABLE_SERIAL_LOG | ||
| -DLOG_LEVEL=1 ; Set log level to info for release candidate builds |
There was a problem hiding this comment.
In general, I think both RC and release should have the same level=info, WDYT @daveallie ?
|
Asking for extra review from @coderabbitai since the change is large, just have a quick look to see if any log statement are mislabeled (for example, LOG_INF --> LOG_ERR and vice versa) |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
🏁 Script executed: Length of output: 14592
Issues FoundMany LOG_DBG statements with "Could not", "Failed to", or "Cannot" messages appear to be error conditions that would prevent the application from functioning correctly. Here are the main categories: 1. File I/O and Parsing Errors (should be LOG_ERR)2. Memory Allocation and Setup Failures (should be LOG_ERR)3. Cache Writing Failures (should be LOG_ERR)4. Data Processing Failures (should be LOG_ERR)5. Runtime State Errors (should be LOG_ERR)6. Serious Warnings (should be LOG_ERR)Legitimate LOG_DBG UsageThese are correctly labeled as debug:
RecommendationConsider changing all LOG_DBG messages that indicate failure conditions (starting with "Could not", "Failed to", "Cannot", "Warning: Could not") to LOG_ERR, as these represent actual errors that users would want to see even at the lowest verbosity level (LOG_LEVEL=0). |
|
@jpirnay also as a safe-guard, I think we can define #ifdef Serial // in case Serial is defined in Arduino header
#undef Serial
#endif
#define Serial static_assert(false && "use LOG_* macro instead"); |
My naive attempt to do that in Logging.h like this: will cause framework libraries to fail compiling |
|
Something like this will work: static HWCDC& logSerial = Serial;
...
class MySerialImpl : public Print {
public:
void begin(unsigned long baud) {
logSerial.begin(baud);
}
__attribute__((deprecated("Use LOG_* macro instead")))
size_t printf(const char * format, ...);
size_t write(uint8_t b) override;
size_t write(const uint8_t* buffer, size_t size) override;
void flush() override;
static MySerialImpl instance;
};
#define Serial MySerialImpl::instance
The version above is quite draft, please adapt it properly. Not sure if there are any |
|
That works now as intended - thank you for your guidance
|
|
I managed to save ~10KB flash space via the last commit, please give it a try |
|
Having slim build is nice, but I think the default build with all debugging messages enabled will always be the common denominator |
|
Build from current master branch gives me firmware.bin size 6302416 bytes, default build from this PR's branch - 6294336 bytes. About 8kb size reduction, nice |
* master: feat: use pre-compressed HTML pages (crosspoint-reader#861) docs: Add requirement device be on when flashing (crosspoint-reader#877) fix: Account for `nbsp;` character as non-breaking space (crosspoint-reader#757) feat: Add central logging pragma (crosspoint-reader#843)
## Summary
* Definition and use of a central LOG function, that can later be
extended or completely be removed (for public use where debugging
information may not be required) to save flash by suppressing the
-DENABLE_SERIAL_LOG like in the slim branch
* **What changes are included?**
## Additional Context
* By using the central logger the usual:
```
#include <HardwareSerial.h>
...
Serial.printf("[%lu] [WCS] Obfuscating/deobfuscating %zu bytes\n", millis(), data.size());
```
would then become
```
#include <Logging.h>
...
LOG_DBG("WCS", "Obfuscating/deobfuscating %zu bytes", data.size());
```
You do have ``LOG_DBG`` for debug messages, ``LOG_ERR`` for error
messages and ``LOG_INF`` for informational messages. Depending on the
verbosity level defined (see below) soe of these message types will be
suppressed/not-compiled.
* The normal compilation (default) will create a firmware.elf file of
42.194.356 bytes, the same code via slim will create 42.024.048 bytes -
170.308 bytes less
* Firmware.bin : 6.469.984 bytes for default, 6.418.672 bytes for slim -
51.312 bytes less
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _NO_
---------
Co-authored-by: Xuan Son Nguyen <[email protected]>
## Summary
* Definition and use of a central LOG function, that can later be
extended or completely be removed (for public use where debugging
information may not be required) to save flash by suppressing the
-DENABLE_SERIAL_LOG like in the slim branch
* **What changes are included?**
## Additional Context
* By using the central logger the usual:
```
#include <HardwareSerial.h>
...
Serial.printf("[%lu] [WCS] Obfuscating/deobfuscating %zu bytes\n", millis(), data.size());
```
would then become
```
#include <Logging.h>
...
LOG_DBG("WCS", "Obfuscating/deobfuscating %zu bytes", data.size());
```
You do have ``LOG_DBG`` for debug messages, ``LOG_ERR`` for error
messages and ``LOG_INF`` for informational messages. Depending on the
verbosity level defined (see below) soe of these message types will be
suppressed/not-compiled.
* The normal compilation (default) will create a firmware.elf file of
42.194.356 bytes, the same code via slim will create 42.024.048 bytes -
170.308 bytes less
* Firmware.bin : 6.469.984 bytes for default, 6.418.672 bytes for slim -
51.312 bytes less
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _NO_
---------
Co-authored-by: Xuan Son Nguyen <[email protected]>
Summary
Definition and use of a central LOG function, that can later be extended or completely be removed (for public use where debugging information may not be required) to save flash by suppressing the -DENABLE_SERIAL_LOG like in the slim branch
What changes are included?
Additional Context
would then become
You do have
LOG_DBGfor debug messages,LOG_ERRfor error messages andLOG_INFfor informational messages. Depending on the verbosity level defined (see below) soe of these message types will be suppressed/not-compiled.AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? NO