class utils::LogReader

Overview

Log - accumulate typed messages reported by the application. Includes percentage value in range <0,1>. More…

#include <LogReader.h>

class LogReader {
public:
    // construction

    LogReader();
    LogReader(const LogReader&);
    LogReader(LogReader&&);
    ~LogReader();

    // methods

    LogReader& operator=(const LogReader&);
    LogReader& operator=(LogReader&&);
    bool IsPercentageEnabled() const;
    float GetPercentage() const;
    void SetOutputStream(std::ostream* output_log_stream);
    std::ostream* GetOutputStream();
    std::vector<std::shared_ptr<LogEntry>> ViewUnread(const utils::EnumFlags<LogEntry::Type>& types = LogEntry::GetWECTypes()) const;
    std::string ViewUnreadToString(const utils::EnumFlags<LogEntry::Type>& types = LogEntry::GetIWECTypes()) const;
    std::vector<std::shared_ptr<LogEntry>> ReadUnread(const utils::EnumFlags<LogEntry::Type>& types);

protected:
    // fields

    std::ostream* output_stream_ = nullptr;
    ProgressPercentage percentage_;
    std::mutex percentage_access_;
    std::vector<std::shared_ptr<LogEntry>> log_entries_;
    std::mutex log_access_;
};

Detailed Documentation

Log - accumulate typed messages reported by the application. Includes percentage value in range <0,1>.

Is not a singleton. Multiple individual components of the application may have their own log.

Includes the functionality to inform about progress of processing functions. Whenever a function is run, this class provides thread-safe getters which can be used to inform user about current state of the function.

Fields

std::vector<std::shared_ptr<LogEntry>> log_entries_

Saved log entries.

std::mutex log_access_

mutex to ensure thread safety of the Log.

Methods

bool IsPercentageEnabled() const

Returns true if percentage is currently enabled. Some processing functions may not support percentage values.

float GetPercentage() const

Returns current percentage value of progress in range 0, 1.

void SetOutputStream(std::ostream* output_log_stream)

Allows user to specify custom output stream to receive verbose information about progress. Default value is nullptr.

std::ostream* GetOutputStream()

Returns pointer to currently active output stream.

std::vector<std::shared_ptr<LogEntry>> ViewUnread(const utils::EnumFlags<LogEntry::Type>& types = LogEntry::GetWECTypes()) const

Get all unread messages specified by their types and return them.

std::string ViewUnreadToString(const utils::EnumFlags<LogEntry::Type>& types = LogEntry::GetIWECTypes()) const

Get all unread messages specified by their types and return them and output as std::string.

std::vector<std::shared_ptr<LogEntry>> ReadUnread(const utils::EnumFlags<LogEntry::Type>& types)

Get all unread messages specified by their types, set them to read, and return them.