Qx v0.5.7
Qt Extensions Library
|
The ApplicationLogger class acts as a convenient means of producing an execution log for an application. More...
#include <qx/io/qx-applicationlogger.h>
Public Member Functions | |
ApplicationLogger () | |
ApplicationLogger (const QString &filePath) | |
ApplicationLogger (const QString &filePath, const QCoreApplication *app) | |
QString | applicationArguments () const |
QString | applicationName () const |
QString | applicationVersion () const |
QString | filePath () const |
IoOpReport | finish (int returnCode) |
bool | hasError () const |
bool | isOpen () const |
int | maximumEntries () const |
IoOpReport | openLog () |
IoOpReport | recordErrorEvent (const QString &src, const Error &error) |
IoOpReport | recordGeneralEvent (const QString &src, const QString &event) |
IoOpReport | recordVerbatim (const QString &text) |
void | resetStatus () |
void | setApplicationArguments (const QString &args) |
void | setApplicationArguments (const QStringList &args) |
void | setApplicationName (const QString &name) |
void | setApplicationVersion (const QString &version) |
void | setFilePath (const QString &path) |
void | setMaximumEntries (int max) |
IoOpReport | status () const |
Often it is useful for an applications to produce a log file that provides additional information about its inner-workings in order to assist with debugging, optimization, or error resolution.
ApplicationLogger simplifies this process by providing a simple interface through which to record basic information about an application and record events/errors with automatic timestamps.
Details of your application should be provided via the classes various setters.
Qx::ApplicationLogger::ApplicationLogger | ( | ) |
Creates an application logger with no file path or details set.
Qx::ApplicationLogger::ApplicationLogger | ( | const QString & | filePath | ) |
Creates an application logger set to record to the file at filePath.
Qx::ApplicationLogger::ApplicationLogger | ( | const QString & | filePath, |
const QCoreApplication * | app ) |
Creates an application logger set to record to the file at filePath.
The details of the application (name, version, and arguments) are automatically set using the application instance app.
QString Qx::ApplicationLogger::applicationArguments | ( | ) | const |
Returns the arguments string of the application that will be recorded in the log.
QString Qx::ApplicationLogger::applicationName | ( | ) | const |
Returns the name of the application that will be recorded in the log.
QString Qx::ApplicationLogger::applicationVersion | ( | ) | const |
Returns the version of the application that will be recorded in the log.
QString Qx::ApplicationLogger::filePath | ( | ) | const |
Returns the path of the log file that the logger is set to record to.
IoOpReport Qx::ApplicationLogger::finish | ( | int | returnCode | ) |
Writes a footer to the current log entry that notes the application's return code and whether or not execution finished successfully, then closes the log. The return code is reinterpreted as an unsigned integer before it's printed.
If returnCode equals 0
, execution is considered to have been successful; otherwise, it will be considered to have ended prematurely.
bool Qx::ApplicationLogger::hasError | ( | ) | const |
bool Qx::ApplicationLogger::isOpen | ( | ) | const |
int Qx::ApplicationLogger::maximumEntries | ( | ) | const |
Returns the maximum number of entries allowed in the log before the oldest entry is purged.
The default is 100
.
IoOpReport Qx::ApplicationLogger::openLog | ( | ) |
Opens the log for recording, writes the log entry heading and basic application information, and returns a report noting if the operation succeeded or failed.
IoOpReport Qx::ApplicationLogger::recordErrorEvent | ( | const QString & | src, |
const Error & | error ) |
Records error to the log with a timestamp and label that denotes the error's severity.
The parameter src acts as a means to identify which section of the application the error originated from, whether it be a source file name, class name, etc.
IoOpReport Qx::ApplicationLogger::recordGeneralEvent | ( | const QString & | src, |
const QString & | event ) |
Records event to the log with a timestamp.
The parameter src acts as a means to identify which section of the application the error originated from, whether it be a source file name, class name, etc.
IoOpReport Qx::ApplicationLogger::recordVerbatim | ( | const QString & | text | ) |
Records text to the log directly as provided with no timestamp or list item separator and terminates it with a newline.
void Qx::ApplicationLogger::resetStatus | ( | ) |
Resets the status of the logger.
void Qx::ApplicationLogger::setApplicationArguments | ( | const QString & | args | ) |
Sets the arguments string of the application that will be recorded in the log to args.
If no arguments are set or the provided argument string is empty, the log will record the application's arguments as *None*
.
void Qx::ApplicationLogger::setApplicationArguments | ( | const QStringList & | args | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
args are joined together into a single string using spaces as a separator.
void Qx::ApplicationLogger::setApplicationName | ( | const QString & | name | ) |
Sets the name of the application that will be recorded in the log to name.
void Qx::ApplicationLogger::setApplicationVersion | ( | const QString & | version | ) |
Sets the version of the application that will be recorded in the log version.
void Qx::ApplicationLogger::setFilePath | ( | const QString & | path | ) |
Sets the path of the log file that the logger will use for recording to path.
The file is appended to with a newline separating the new log entry from the previous entry.
void Qx::ApplicationLogger::setMaximumEntries | ( | int | max | ) |
Sets the maximum number of entries to be kept in the log before the oldest one is purged.
IoOpReport Qx::ApplicationLogger::status | ( | ) | const |
Returns the error status of the logger.
The status is a report of the last operation performed by ApplicationLogger. If no operation has been performed since the logger was constructed or resetStatus() was last called the report will be null.