class EE::System::Log

Overview

Global log file. The engine will log everything in this file. More…

#include <log.hpp>

class Log: protected EE::System::Mutex {
public:
    // construction

    virtual ~Log();

    // methods

    static std::unordered_map<std::string, LogLevel> getMapFlag();
    static constexpr LogLevel getDefaultLogLevel();
    static Log* create(const std::string& logPath, const LogLevel& level, bool stdOutLog, bool liveWrite);
    static Log* create(const LogLevel& level, bool stdOutLog, bool liveWrite);
    static void debug(const std::string_view& text);
    static void info(const std::string_view& text);
    static void notice(const std::string_view& text);
    static void warning(const std::string_view& text);
    static void error(const std::string_view& text);
    static void critical(const std::string_view& text);
    static void assertLog(const std::string_view& text);

    template <class... Args>
    static void debug(const char* format, Args&&... args);

    template <class... Args>
    static void info(const char* format, Args&&... args);

    template <class... Args>
    static void notice(const char* format, Args&&... args);

    template <class... Args>
    static void warning(const char* format, Args&&... args);

    template <class... Args>
    static void error(const char* format, Args&&... args);

    template <class... Args>
    static void critical(const char* format, Args&&... args);

    template <class... Args>
    static void assertLog(const char* format, Args&&... args);

    void save(const std::string& filepath = "");
    void write(const std::string_view& text);
    void write(const LogLevel& level, const std::string_view& text);
    void writel(const std::string_view& text);
    void writel(const LogLevel& level, const std::string_view& text);

    template <typename... Args>
    void writef(const LogLevel& level, std::string_view format, Args&&... args);

    template <typename... Args>
    void writef(std::string_view format, Args&&... args);

    const std::string& getBuffer() const;
    const bool& isLoggingToStdOut() const;
    void setLogToStdOut(const bool& output);
    const bool& isLiveWrite() const;
    void setLiveWrite(const bool& lw);
    void addLogReader(LogReaderInterface* reader);
    void removeLogReader(LogReaderInterface* reader);
    const LogLevel& getLogLevelThreshold() const;
    void setLogLevelThreshold(const LogLevel& logLevelThreshold);
    const std::string& getFilePath() const;
    void setFilePath(const std::string& filePath);
    bool getKeepLog() const;
    void setKeepLog(bool keepLog);
};

Inherited Members

public:
    // methods

    void lock();
    void unlock();
    int tryLock();

Detailed Documentation

Global log file. The engine will log everything in this file.

Methods

void save(const std::string& filepath = "")

Indicates that the log must be writed to a file when the Log instance is closed.

Parameters:

filepath

The path to the file to write the log.

void write(const std::string_view& text)

Writes the text to the log.

Parameters:

text

The text to write

void write(const LogLevel& level, const std::string_view& text)

Writes the text to the log with a log level.

Parameters:

level

The log level that will try to write.

text

The text to write

void writel(const std::string_view& text)

Writes the text to the log and appends a new line character at the end.

Parameters:

text

The text to write

void writel(const LogLevel& level, const std::string_view& text)

Writes the text to the log and appends a new line character at the end with a log level.

Parameters:

levelThe

log level that will try to write.

text

The text to write

template <typename... Args>
void writef(const LogLevel& level, std::string_view format, Args&&... args)

Writes a formated string to the log with a log level.

Parameters:

level

The log level that will try to write.

format

The Text format.

template <typename... Args>
void writef(std::string_view format, Args&&... args)

Writes a formated string to the log.

const std::string& getBuffer() const

Returns:

A reference of the current writed log.

const bool& isLoggingToStdOut() const

Returns:

If the log Writes are outputed to stdout.

void setLogToStdOut(const bool& output)

Enabled or disables to output the Writes to stdout.

const bool& isLiveWrite() const

Returns:

If the file is forced to flush the data on every Write call.

void setLiveWrite(const bool& lw)

Activate or deactivate to flush the writed data to the log on every Write call.

void addLogReader(LogReaderInterface* reader)

Adds a reader interface. The reader interface is used to the informed for every writed text to the log.

void removeLogReader(LogReaderInterface* reader)

Removes the reader interface.

const LogLevel& getLogLevelThreshold() const

Returns:

The log level threshold.

void setLogLevelThreshold(const LogLevel& logLevelThreshold)

Sets the log level threshold. This is the minimum level that message will actually be logged.

const std::string& getFilePath() const

Returns:

The file path of the log file (if any).

void setFilePath(const std::string& filePath)

Sets the file path of the log file.

bool getKeepLog() const

Returns:

True if the logs are being buffered in memory

void setKeepLog(bool keepLog)

Enable/Disable to keep a copy of the logs into memory (disabled by default)