logging lib
This commit is contained in:
@@ -4,8 +4,15 @@
|
||||
#define LCD_LINES 4
|
||||
#define LCD_COLS 40
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <log.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <print>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <gpu_metrics.hpp>
|
||||
#include <print>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
#define REL_METRICS_PATH "/../../gpu_metrics" // gpu_metrics path relative to hwmon path
|
||||
#define MAX_METRICS_LENGTH 512 // length of the metrics buffer
|
||||
#define REL_METRICS_PATH "/../../gpu_metrics" // gpu_metrics path relative to hwmon path
|
||||
#define MAX_METRICS_LENGTH 512 // length of the metrics buffer
|
||||
|
||||
/* clean abstraction for gpu_metrics or metrics in filesystem in sane units */
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <ArduinoJson.hpp>
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
|
||||
#define HASS_TOKEN "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0MzUxMTZiY2VjNTg0MTI3OGI4YmU0NTY4ZGQ5MzIyYiIsImlhdCI6MTc1NzQzMDI0MCwiZXhwIjoyMDcyNzkwMjQwfQ.6wKTlxEA0FLWfv-qW35vewUSvTxdVrZWqFwHT5Khu6E"
|
||||
|
||||
39
include/log.hpp
Normal file
39
include/log.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef LOG_HPP
|
||||
#define LOG_HPP
|
||||
|
||||
// #define PATTERN "[{}{}{}] "
|
||||
|
||||
#include <mutex>
|
||||
#include <print>
|
||||
#include <string_view>
|
||||
|
||||
enum class LOG { INF, WRN, ERR, DBG };
|
||||
inline std::mutex mtx;
|
||||
|
||||
template <typename... Args>
|
||||
inline void log(LOG level, std::string_view tag, std::format_string<Args...> str, Args&&... args) {
|
||||
constexpr std::string_view reset = "\033[0m";
|
||||
constexpr std::string_view green = "\033[32m";
|
||||
constexpr std::string_view yellow = "\033[33m";
|
||||
constexpr std::string_view red = "\033[31m";
|
||||
constexpr std::string_view pattern = "[{}{}{}] ";
|
||||
|
||||
std::scoped_lock lock(mtx);
|
||||
switch (level) {
|
||||
case LOG::INF:
|
||||
std::print(pattern, green, tag, reset);
|
||||
break;
|
||||
case LOG::WRN:
|
||||
std::print(pattern, yellow, tag, reset);
|
||||
break;
|
||||
case LOG::ERR:
|
||||
std::print(pattern, red, tag, reset);
|
||||
break;
|
||||
default:
|
||||
std::print(pattern, "", tag, "");
|
||||
}
|
||||
|
||||
std::println(str, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <print>
|
||||
#include <log.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user