MFlogger

current time, formatting and logging

mflogger Library - Version: 3.1.6

Please read 'COPYING' for license terms
To use in your code include the MFlogger header
 
There are four classes: logger, jsonlog, syslog & timestring e.g. log data to a file
mflogger::logger loggingfile();
loggingfile.log();
loggingfile.log();
This will result in something like this in the log file
2025-11-01T07:24:35 there is something fishy going on
2025-11-01T07:24:36 Barracuda
e.g. log json data to a file
mflogger::jsonlog loggingfile();
loggingfile.log(, , );
loggingfile.log(, , );
This will result in something like this in the log file
{:,:,:}
{:,:,:}
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();
std::vector<std::pair<std::string, std::string> > values;
values.push_back(std::make_pair(, ));
values.push_back(std::make_pair(, ));
values.push_back(std::make_pair(, ));
jlog.log(values, );
This will result in something like this in the log file
{:,:,:,:,:}
By default logging happens using local time in iso 8601 format.
This can be changed using the timeformat function. This function uses std::put_time formatting syntax or can be used with mflogger::timestring::format as an argument
e.g.
loggingfile.timeformat(mflogger::timestring::format::HMS24);  
  
loggingfile.timeformat();
e.g. using mfsyslog
mflogger::mfsyslog log;
log.log(LOG_INFO, );
this should log using the syslog daemon

Please look at logexample.cpp for examples
mflogger::logger Interface

logger( std::string& logfilename, & append = , timestring::format prefix = timestring::format::iso8601);
logger(); 


 open( std::string& logfilename, & append = );


 good() ;
 is_open() ;


std::string log( std::string& message);



std::string log_epoch( std::string& message, timestring::precision p = timestring::precision::sec);


logger& <<( std::string& in);
logger& <<( in);
logger& <<( in);



 setdelimiter( std::string& d);
mflogger::jsonlog Interface derived from mflogger::log

jsonlog( std::string& logfilename, & append = , timestring::format prefix = timestring::format::iso8601);
jsonlog(); 


std::string log( std::string& logitem,  std::string& value,  std::string& level = );


std::string log( std::vector<std::pair<std::string, std::string> >& logdata,  std::string& level = );

mflogger::mfsyslog Interface

mfsyslog( std::string& Prepend = ,  option = 0,  facility = 0);


 log( priority,  std::string& data);

timestring

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 = )


 timeformat( std::string& FORMAT); { 



 timeformat(format FORMAT);
mflogger Library - Version: 3.1.6