mitteLib
Loading...
Searching...
No Matches
log.hpp
Go to the documentation of this file.
1//
2// Created by spak on 03/09/24.
3//
4
5#ifndef LOG_HPP
6#define LOG_HPP
7
8#ifdef ESP_PLATFORM
9
10#include <esp_log.h>
11
12#define LOGE ESP_LOGE
13#define LOGW ESP_LOGW
14#define LOGI ESP_LOGI
15#define LOGD ESP_LOGD
16#define LOGV ESP_LOGV
17
18#else
19
20#include <chrono>
21#include <cstdio>
22
23namespace mlab {
24 [[nodiscard]] std::uint32_t log_timestamp();
25}
26
27#define MLAB_LOG_COLOR_E "\033[0;31m"
28#define MLAB_LOG_COLOR_W "\033[0;33m"
29#define MLAB_LOG_COLOR_I "\033[0;32m"
30#define MLAB_LOG_COLOR_D
31#define MLAB_LOG_COLOR_V
32#define MLAB_LOG_RESET_COLOR "\033[0m"
33#define MLAB_LOG_FORMAT(letter, format) MLAB_LOG_COLOR_##letter #letter " (%u) %s: " format MLAB_LOG_RESET_COLOR "\n"
34
35#define LOGE(tag, format, ...) \
36 do { std::printf((MLAB_LOG_FORMAT(E, format)), ::mlab::log_timestamp(), tag, ##__VA_ARGS__); } while (false)
37#define LOGW(tag, format, ...) \
38 do { std::printf((MLAB_LOG_FORMAT(W, format)), ::mlab::log_timestamp(), tag, ##__VA_ARGS__); } while (false)
39#define LOGI(tag, format, ...) \
40 do { std::printf((MLAB_LOG_FORMAT(I, format)), ::mlab::log_timestamp(), tag, ##__VA_ARGS__); } while (false)
41#define LOGD(tag, format, ...) \
42 do { std::printf((MLAB_LOG_FORMAT(D, format)), ::mlab::log_timestamp(), tag, ##__VA_ARGS__); } while (false)
43#define LOGV(tag, format, ...) \
44 do { std::printf((MLAB_LOG_FORMAT(V, format)), ::mlab::log_timestamp(), tag, ##__VA_ARGS__); } while (false)
45
46#endif
47
48#endif//LOG_HPP
Definition log.cpp:8
std::uint32_t log_timestamp()
Definition log.cpp:11