sfuphantom / DAQ

0 stars 0 forks source link

Logging Wrapper Added #23

Closed Andromas14 closed 1 year ago

Andromas14 commented 1 year ago

Purpose

A versatile logging wrapper, allowing for the change of logging libraries by only customizing 2 scripts: Log.cpp and Log.h. Thus there won't be a need to rewrite code in any other scripts if there is a change to a different logging library.

Currently using the ArduinoLog library.

Implementation

Header needs to include Log.h and be using namespace Logger. On device setup, call Start() or Logger::Start() function to initialize the logging system. The Log level parameter in the Log.begin() function can be changed to set the lowest log level displayed, and filter out messages that are lower level than the parameter. This may also be changed at runtime via Logging::setLevel() function from the ArduinoLog.

To create a log message use one of the 6 Log level functions with an accompanying message string.

Available Log Levels: Verbose, Trace, Notice, Info, Warning, Error, Fatal.

The input can print variables in the same way as the printf() function.

Example Code: Info("Logging System Start Success"); Will output: 17:20:10:38 [Info] : Logging System Start Success Using the format: _TIME_FROM_SETUP [LOGLEVEL] : LOG INPUT STRING

The Logger namespace has functions in it to initalize the format of the messages, these are called within the Start() method. They can be modified in order to customize the message format as needed, but are using the ArduinoLog library, other libaries.

Current functions set the prefix (Timestamp, Log Level) and the suffix (currently nothing, can be changed if needed), with the input log string being put in between.

The timestamp uses the millis() function, which counts time from the startup of the device. It can be changed to a realtime clock timestamp, but may require an outside connection to sync with the local time, or will need to be manually set thorugh code.

Testing

To be tested using an ESP32, compiles without errors

References

https://github.com/thijse/Arduino-Log https://docs.google.com/document/d/1bXmvKOGXHvtMauRjWnox6od5YsSQDtnRrv-VulEEWuo/edit?usp=sharing https://github.com/orgs/sfuphantom/projects/2?pane=issue&itemId=17585626