AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ALogger Class Referencefinal

A logger class. More...

Detailed Description

A logger class.

Logger is used for journaling application events like errors or some user actions.

It provides some extra functions like logging to file and output formatting.

It provides std::cout-like API.

Example:

ALogger::info("MyApp") << "Hello world!";

Possible output:

[00:47:02][UI Thread][Logger][INFO]: Hello world!

It's convenient to define LOG_TAG variable for your class:

static constexpr auto LOG_TAG = "MyDownloader";
class MyDownloader {
public:
void someAction() {
ALogger::info(LOG_TAG) << "someAction() called";
}
void downloadFile(const AString& name) {
ALogger::info(LOG_TAG) << "Downloading file: " << name;
}
}
Represents a Unicode character string.
Definition: AString.h:37

Classes

struct  LogWriter
 

Public Types

enum  Level { INFO , WARN , ERR , DEBUG }
 

Public Member Functions

 ALogger (AString filename)
 Constructor for an extra log file. More...
 
void setDebugMode (bool debug)
 
bool isDebug ()
 
void setLogFile (APath path)
 Sets log file. More...
 
APath logFile ()
 
void onLogged (std::function< void(const AString &prefix, const AString &message, Level level)> callback)
 
template<aui::invocable Callable>
void doLogFileAccessSafe (Callable action)
 Allows to perform some action (access safely) on log file (which is opened all over the execution process) More...
 
LogWriter log (Level level, const AString &prefix)
 Writer a log entry with LogWriter helper. More...
 

Static Public Member Functions

static ALoggerglobal ()
 
static void setLogFileForGlobal (APath path)
 Sets log file for ALogger::global(). More...
 
static LogWriter info (const AString &str)
 
static LogWriter warn (const AString &str)
 
static LogWriter err (const AString &str)
 
static LogWriter debug (const AString &str)
 

Constructor & Destructor Documentation

◆ ALogger()

ALogger::ALogger ( AString  filename)
inline

Constructor for an extra log file.

Parameters
filenamefile name

For the global logger, use ALogger::info, ALogger::warn, etc...

Member Function Documentation

◆ doLogFileAccessSafe()

template<aui::invocable Callable>
void ALogger::doLogFileAccessSafe ( Callable  action)
inline

Allows to perform some action (access safely) on log file (which is opened all over the execution process)

Useful when sending log file to remote server.

Note
Windows, for instance, doesn't allow to read the file when it's already opened

◆ log()

LogWriter ALogger::log ( Level  level,
const AString prefix 
)
inline

Writer a log entry with LogWriter helper.

Parameters
levellevel
prefixprefix

◆ setLogFile()

void ALogger::setLogFile ( APath  path)
inline

Sets log file.

Parameters
pathpath to the log file.

Log file is opened immediately in setLogFile.

Note
If you want to change the log file of ALogger::global(), consider using ALogger::setLogFileForGlobal instead. ALogger::global().setLogFile(...) expression would cause the default log file location to open and to close immediately, when opening a log file in the specified location, causing empty file and two Log file: entries.

◆ setLogFileForGlobal()

void ALogger::setLogFileForGlobal ( APath  path)
static

Sets log file for ALogger::global().

Parameters
pathpath to the log file.
See also
ALogger::setLogFile

#include <AUI/Logging/ALogger.h>


The documentation for this class was generated from the following files: