Skip to content

Conversation

@Abasz
Copy link

@Abasz Abasz commented Jul 7, 2025

Description

This pull request introduces several improvements and modernizations to the Arduino-Log library as suggested by #8:

1. Log Level as enum class

  • Replaces legacy log level macros with a strongly-typed enum class ArduinoLogLevel.

2. Backward Compatibility

  • No breaking changes: Existing code using the old macros or integer log levels will continue to work.
  • All previous macro names (LOG_LEVEL_ERROR, etc.) are still available for existing code (in constexpr alias).
  • Overloads for int log level arguments are retained for legacy support, with safe conversion to the new enum (using the highest/lowest log level if passed int is out of bounds).

3. Macro Conflict Handling

  • Detects and saves any existing LOG_LEVEL_* macro definitions before undefining them.
  • Restores the original macro values at the end of the header file.
  • Prevents conflicts with other libraries (such as NimBLE) that may define their own log level macros.

Potential Impact

  • Existing code should continue to work without modification.
  • Other libraries' macros are preserved and restored, minimizing integration issues.
  • Type safety is improved for new code using the enum class.

Notes

  • If any user code or third-party library relies on complex macro expansions for conflicted named log levels, the macro save/restore logic may not work properly, but this should be a very very edge case.
  • This PR does not change the public API, but modernizes the internals.

Abasz added 5 commits July 6, 2025 21:17
Fix the `printTimestamp` and `printCarret` call signature to match
`printfunction` typedef.
Move writeLog definition into the header file. Fixes JSC-TechMinds#9.
(JSC-TechMinds#9)
Add `ArduinoLogLevel` enum to replace int log levels. Update code to use
the new enum type for log levels as well as add backward compatibility
for existing int-based log level usage. This change improves type safety
and readability of the code and most importantly fixes naming collision
with nimble log levels.
Add undefine for old log level macros to avoid conflicts with other
libraries (e.g. NimBLE) while keeping backward compatibility
This ensures that the ArduinoLog library can be used without issues
related to naming collisions. However, this may not 100% safe as include
order will matter and that potentially can break other code that uses
these macros and included after ArduinoLog.h.
When including ArduinoLog save any existing definitions of LOG_LEVEL_*
macros (e.g. from NimBLE) so that they can be restored after ArduinoLog
is included to avoid compilation errors. This allows this library to
coexist with others while keeping backward compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant