32static string getLevelString(uint8_t level)
47 return std::to_string(level);
51static string truncateFileName(
const string& name,
int depth = 0)
54 auto start = name.find_last_of(
"\\/");
57 for (
int i = 0; i < depth && start != string::npos; i++)
58 start = name.find_last_of(
"\\/", start - 1);
61 return start == string::npos
63 :
"..." +
string{name.cbegin() + start, name.cend()};
68 using namespace fmt::literals;
69 if (record.level >= minimumLevel)
73 string tsStr = fmt::format(
"{:02d}:{:06.3f}", min, (ts - min * 60));
76 format,
"ts"_a = tsStr,
"file"_a = truncateFileName(record.file, 1),
79 "fun"_a = record.function,
"lvl"_a = getLevelString(record.level),
80 "name"_a = record.name,
"msg"_a = record.message));
86 Lock<FastMutex> lock(
mutex);
87 fwrite(l.c_str(),
sizeof(
char), l.length(),
f);
92 Lock<FastMutex> lock(
mutex);
94 strncpy(s.logString, l.c_str(), MAX_LOG_STRING_SIZE - 1);
100 return PrintLogger(parent, this->name +
"." + name);
103LogRecord PrintLogger::buildLogRecord(uint8_t level,
const string& function,
104 const string& file,
int line,
105 fmt::string_view format,
106 fmt::format_args args)
109 record.
level = level;
110 record.function = function;
116 record.message = fmt::vformat(format, args);
118 catch (
const std::exception& e)
121 record.message =
"FMT Formatting error! " + string(e.what());
127void PrintLogger::vlog(uint8_t level,
const string& function,
128 const string& file,
int line, fmt::string_view format,
129 fmt::format_args args)
131 parent.log(buildLogRecord(level, function, file, line, format, args));
134void PrintLogger::vlogAsync(uint8_t level,
const string& function,
135 const string& file,
int line,
136 fmt::string_view format, fmt::format_args args)
138 parent.logAsync(buildLogRecord(level, function, file, line, format, args));
141void Logging::log(
const LogRecord& record)
143 for (
auto& s : sinks)
148void Logging::logAsync(
const LogRecord& record) { asyncLog.log(record); }
150Logging::AsyncLogger::AsyncLogger(Logging& parent) : parent(parent) {}
152void Logging::AsyncLogger::log(
const LogRecord& record)
155 Lock<FastMutex>
l(mutex);
162void Logging::AsyncLogger::run()
164 while (!shouldStop())
168 Lock<FastMutex>
l(mutex);
169 while (records.isEmpty())
if(canDrivers[canDev]) canDrivers[canDev] -> handleRXInterrupt(fifo)
void logImpl(const std::string &l) override
void logImpl(const std::string &l) override
void log(const LogRecord &record)
virtual void logImpl(const std::string &l)=0
LoggerResult log(const T &t)
Call this function to log a class.
PrintLogger(Logging &logging, const string &name)
PrintLogger getChild(const string &name)
long long getOldTick()
Get the current time in milliseconds.
This file includes all the types the logdecoder script will decode.