#include <mflogger.h>
There are three classes: log, jsonlog & timestring
mflogger::log loggingfile("/path/to/log/file.log");
loggingfile.logmessage("there is something fishy going on");
loggingfile.logmessage("Barracuda");
This will result in something like this in the log file
2024-11-01T07:24:35 there is something fishy going on
2024-11-01T07:24:36 Barracuda
e.g. log json data to a file
mflogger::jsonlog loggingfile("/path/to/log/file.log");
loggingfile.logjson("what's up", "there is something fishy going on", "info");
loggingfile.logjson("fish", "Barracuda", "oh no");
This will result in something like this in the log file
{"level":"info","timestamp":"2024-11-30T19:16:15,"what's up":"there is something fishy going on"}
{"level":"oh no","timestamp":"2024-11-30T19:16:15,"fish":"Barracuda"}
e.g. You can use the std::vector version of the jsonlog class to add as many values as you wish in a log message
mflogger::jsonlog loggingfile("/path/to/log/file.log");
std::vector<std::pair<std::string, std::string> > values;
values.push_back(std::make_pair("hello", "world"));
values.push_back(std::make_pair("pointless", "query"));
values.push_back(std::make_pair("pi", "3.14159265358979323846"));
jlog.logjson(values, "trace");
This will result in something like this in the log file
{"level":"trace","timestamp":"2024-11-30T19:16:15EDT","hello":"world","pointless":"query","pi":"3.14159265358979323846"}
By default logging happens using local time in iso 8601 format.loggingfile.timeformat(mflogger::timestring::format::HMS24);
loggingfile.timeformat("Making up a logging line prefix %H:%M);
Please look at logexample.cpp for examples
log(const std::string& logfilename, const bool& append = true, timestring::format prefix = timestring::format::iso8601);
bool open(const std::string& logfilename, const bool& append = true);
bool good() const;
bool is_open() const;
std::string logmessage(const std::string& message);
std::string logmessage_epoch(const std::string& message, timestring::precision p = timestring::precision::sec);
log& operator<<(const std::string& in);
log& operator<<(bool in);
log& operator<<(char in);
void setdelimiter(const std::string& d);
mflogger::jsonlog Interface derived from mflogger::log
jsonlog(const std::string& logfilename, const bool& append = true, timestring::format prefix = timestring::format::iso8601);
std::string logjson(const std::string& logitem, const std::string& value, const std::string& level = "");
std::string logjson(const std::vector<std::pair<std::string, std::string> >& logdata, const std::string& level = "");
Log's Base class timestring can be used just to get local time in a string
Can also be used to format the current time.
e.g.
mflogger::timestring st;
st.time_asstring();
st.epoch_asstring;
st.ISO8601TimeUTC();
mflogger::timestring Interface
timestring(timestring::format f = timestring::format::iso8601);
std::string time_asstring();
std::string epoch_asstring(precision Precision = sec, std::string delimeter = ".")
void timeformat(const std::string& FORMAT); {
void timeformat(format FORMAT);