| openPilotLog

Functions
ALog Namespace Reference

The ALog namespace encapsulates constants and functions used to provide logging to files and logging to console (stdout) More...

## Functions
void | setLogFileName ()
| setLogFileName sets a log file name ("Log_<Date>_<Time>.txt")
void | deleteOldLogs ()
| Cleans up old logs and initializes logging by preparing and installing a QMessageHandler.
bool | init (bool log_debug)
| initialise logging, clean up logfiles and install a QMessageHandler. To enable logging of debug messages, pass parameter as true.
void | aMessageHandler (QtMsgType type, const QMessageLogContext &context, const QString &msg)
| aMessageHandler Intercepts Messages and prints to console and log file More...

## Detailed Description

The ALog namespace encapsulates constants and functions used to provide logging to files and logging to console (stdout)

The console output is color coded - green, amber, magenta for info, warn and crit messages, whereas the log files are just plain text.

There is a maximum of <numberOfLogs> log files with a maximum size of <sizeOfLogs>, at the moment, up to 10 logs of up to 100kB in size are kept, older logs are automatically deleted.

Debug output is not written to the logfile.

In order to start logging, the ALog::init() function has to be called

Credits to Andy Dunkel for his excellent blog post on Qt Log File Rotation!

## Function Documentation

## ◆ aMessageHandler()

void ALog::aMessageHandler | ( | QtMsgType | type,
|  | const QMessageLogContext & | context,
|  | const QString & | msg
| ) |  |

aMessageHandler Intercepts Messages and prints to console and log file

The message handler is responsible for intercepting the output from qDebug(), qInfo(), qWarning() and qCritical(), formatting them and printing them to the standard console out and to a logfile using QTextStream. Debug messages are not written to the log file.