AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ALogger Class Referencefinal

A logger class. More...

#include <AUI/Logging/ALogger.h>

Detailed Description

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:38

Constructor & Destructor Documentation

◆ ALogger()

ALogger::ALogger ( AString filename)
inline
Parameters
filenamefile name

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

Member Function Documentation

> All members, including inherited

◆ doLogFileAccessSafe()

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

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
Parameters
levellevel
prefixprefix

◆ setLogFile()

void ALogger::setLogFile ( APath path)
inline
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()

static void ALogger::setLogFileForGlobal ( APath path)
static
Parameters
pathpath to the log file.
See also
ALogger::setLogFile