mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
Logging improvements & other cleanup (#227)
This commit is contained in:
parent
933bc5fb97
commit
d29e47f0eb
@ -22,9 +22,7 @@ private:
|
||||
lv_obj_t* labelWidget = nullptr;
|
||||
|
||||
static inline bool shouldShowLog(LogLevel filterLevel, LogLevel logLevel) {
|
||||
return (filterLevel != LogLevel::None) &&
|
||||
(logLevel != LogLevel::None) &&
|
||||
filterLevel >= logLevel;
|
||||
return filterLevel >= logLevel;
|
||||
}
|
||||
|
||||
void updateLogEntries() {
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
namespace tt {
|
||||
|
||||
struct LogEntry {
|
||||
LogLevel level = LogLevel::None;
|
||||
LogLevel level = LogLevel::Verbose;
|
||||
char message[TT_LOG_MESSAGE_SIZE] = { 0 };
|
||||
};
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ namespace tt {
|
||||
|
||||
/** Used for log output filtering */
|
||||
enum class LogLevel : int {
|
||||
None = 0, /*!< No log output */
|
||||
Error, /*!< Critical errors, software module can not recover on its own */
|
||||
Warning, /*!< Error conditions from which recovery measures have been taken */
|
||||
Info, /*!< Information messages which describe normal flow of events */
|
||||
|
||||
@ -46,4 +46,5 @@ std::unique_ptr<std::array<LogEntry, TT_LOG_ENTRY_COUNT>> copyLogEntries(std::si
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace tt
|
||||
|
||||
@ -3,8 +3,9 @@
|
||||
#include "Tactility/Log.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <sys/time.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace tt {
|
||||
|
||||
@ -22,23 +23,21 @@ static char toPrefix(LogLevel level) {
|
||||
case Debug:
|
||||
return 'D';
|
||||
case Verbose:
|
||||
return 'T';
|
||||
default:
|
||||
return '?';
|
||||
return 'V';
|
||||
}
|
||||
}
|
||||
|
||||
static const char* toColour(LogLevel level) {
|
||||
static const char* toTagColour(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return "\033[1;31m";
|
||||
case Warning:
|
||||
return "\033[33m";
|
||||
return "\033[1;33m";
|
||||
case Info:
|
||||
return "\033[32m";
|
||||
case Debug:
|
||||
return "\033[1;37m";
|
||||
return "\033[36m";
|
||||
case Verbose:
|
||||
return "\033[37m";
|
||||
default:
|
||||
@ -46,6 +45,21 @@ static const char* toColour(LogLevel level) {
|
||||
}
|
||||
}
|
||||
|
||||
static const char* toMessageColour(LogLevel level) {
|
||||
using enum LogLevel;
|
||||
switch (level) {
|
||||
case Error:
|
||||
return "\033[1;31m";
|
||||
case Warning:
|
||||
return "\033[1;33m";
|
||||
case Info:
|
||||
case Debug:
|
||||
case Verbose:
|
||||
return "\033[0m";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
static uint64_t getLogTimestamp() {
|
||||
static uint64_t base = 0U;
|
||||
struct timeval time {};
|
||||
@ -59,7 +73,7 @@ static uint64_t getLogTimestamp() {
|
||||
|
||||
void log(LogLevel level, const char* tag, const char* format, ...) {
|
||||
std::stringstream buffer;
|
||||
buffer << toColour(level) << toPrefix(level) << " (" << getLogTimestamp() << ") " << tag << ": " << format << "\033[0m\n";
|
||||
buffer << getLogTimestamp() << " [" << toTagColour(level) << toPrefix(level) << "\033[0m" << "] [" << tag << "] " << toMessageColour(level) << format << "\033[0m\n";
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
@ -35,12 +35,12 @@ static const char* toString(InitMode mode) {
|
||||
}
|
||||
|
||||
static void printInfo(const Data& data) {
|
||||
TT_LOG_V(TAG, "I2C info for port %d", data.configuration.port);
|
||||
TT_LOG_V(TAG, " isStarted: %d", data.isStarted);
|
||||
TT_LOG_V(TAG, " isConfigured: %d", data.isConfigured);
|
||||
TT_LOG_V(TAG, " initMode: %s", toString(data.configuration.initMode));
|
||||
TT_LOG_V(TAG, " canReinit: %d", data.configuration.canReinit);
|
||||
TT_LOG_V(TAG, " hasMutableConfiguration: %d", data.configuration.hasMutableConfiguration);
|
||||
TT_LOG_D(TAG, "I2C info for port %d", data.configuration.port);
|
||||
TT_LOG_D(TAG, " isStarted: %d", data.isStarted);
|
||||
TT_LOG_D(TAG, " isConfigured: %d", data.isConfigured);
|
||||
TT_LOG_D(TAG, " initMode: %s", toString(data.configuration.initMode));
|
||||
TT_LOG_D(TAG, " canReinit: %d", data.configuration.canReinit);
|
||||
TT_LOG_D(TAG, " hasMutableConfiguration: %d", data.configuration.hasMutableConfiguration);
|
||||
#ifdef ESP_PLATFORM
|
||||
TT_LOG_V(TAG, " SDA pin: %d", data.configuration.config.sda_io_num);
|
||||
TT_LOG_V(TAG, " SCL pin: %d", data.configuration.config.scl_io_num);
|
||||
|
||||
@ -29,15 +29,15 @@ static const char* toString(InitMode mode) {
|
||||
}
|
||||
|
||||
static void printInfo(const Data& data) {
|
||||
TT_LOG_V(TAG, "SPI info for device %d", data.configuration.device);
|
||||
TT_LOG_V(TAG, " isStarted: %d", data.isStarted);
|
||||
TT_LOG_V(TAG, " isConfigured: %d", data.isConfigured);
|
||||
TT_LOG_V(TAG, " initMode: %s", toString(data.configuration.initMode));
|
||||
TT_LOG_V(TAG, " canReinit: %d", data.configuration.canReinit);
|
||||
TT_LOG_V(TAG, " hasMutableConfiguration: %d", data.configuration.hasMutableConfiguration);
|
||||
TT_LOG_V(TAG, " MISO pin: %d", data.configuration.config.miso_io_num);
|
||||
TT_LOG_V(TAG, " MOSI pin: %d", data.configuration.config.mosi_io_num);
|
||||
TT_LOG_V(TAG, " SCLK pin: %d", data.configuration.config.sclk_io_num);
|
||||
TT_LOG_D(TAG, "SPI info for device %d", data.configuration.device);
|
||||
TT_LOG_D(TAG, " isStarted: %d", data.isStarted);
|
||||
TT_LOG_D(TAG, " isConfigured: %d", data.isConfigured);
|
||||
TT_LOG_D(TAG, " initMode: %s", toString(data.configuration.initMode));
|
||||
TT_LOG_D(TAG, " canReinit: %d", data.configuration.canReinit);
|
||||
TT_LOG_D(TAG, " hasMutableConfiguration: %d", data.configuration.hasMutableConfiguration);
|
||||
TT_LOG_D(TAG, " MISO pin: %d", data.configuration.config.miso_io_num);
|
||||
TT_LOG_D(TAG, " MOSI pin: %d", data.configuration.config.mosi_io_num);
|
||||
TT_LOG_D(TAG, " SCLK pin: %d", data.configuration.config.sclk_io_num);
|
||||
}
|
||||
|
||||
bool init(const std::vector<spi::Configuration>& configurations) {
|
||||
@ -163,9 +163,6 @@ bool isStarted(spi_host_device_t device) {
|
||||
auto lock = getLock(device).asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
Data& data = dataArray[device];
|
||||
Configuration& config = data.configuration;
|
||||
|
||||
return dataArray[device].isStarted;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user