class utils::LogWriter
Overview
Extension to LogReader. Provide write access to the log. More…
#include <LogWriter.h> class LogWriter: public utils::LogReader, public utils::DelegatedNotifier, public utils::DelegatedNotifier { public: // construction LogWriter(); LogWriter(const LogWriter&); LogWriter(utils::LogWriter&&); ~LogWriter(); // methods LogWriter& operator=(const LogWriter&); LogWriter& operator=(utils::LogWriter&&); void ResetPercentage(bool enable_percentage = true); void SetPercentage(float value); LogWriter& operator+=(const float percentage_increment); LogWriter& operator<<(const std::shared_ptr<LogEntry> entry); LogWriter& Add(const LogEntry&& entry); LogWriter& Add(const std::shared_ptr<LogEntry> entry); template <typename ... Params> LogWriter& AddEntry(Params&&... params); LogWriter& Inform(const std::string& message, const std::string& caller_name); LogWriter& Warn(const std::string& message, const std::string& caller_name); LogWriter& Fail(const std::string& message, const std::string& caller_name); LogWriter& Crash(const std::string& message, const std::string& caller_name); template <class CT> LogWriter& Inform(const std::string& message, const utils::NamedClass<CT>* caller); template <class CT> LogWriter& Warn(const std::string& message, const utils::NamedClass<CT>* caller); template <class CT> LogWriter& Fail(const std::string& message, const utils::NamedClass<CT>* caller); template <class CT> LogWriter& Crash(const std::string& message, const utils::NamedClass<CT>* caller); LogWriter& CopyUnreadEntries(const LogReader& other); void StartTimeMeasure(const std::string& measurement_name); void StopTimeMeasure(); bool SaveToFile(const std::string& file_path); bool DisplayUnread(const utils::EnumFlags<utils::LogEntry::Type>& types, const std::function<void(const std::wstring&, const std::wstring&)>& ShowMessageBox = nullptr); };
Inherited Members
public: // typedefs typedef std::function<void(Args...)> CallbackType; // 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); void AddCallback(CallbackType callback); virtual void Notify(Args... args); bool HasCallback() const; virtual void Notify(Args... args); virtual void SendAllNotifications(); virtual void WaitUntilAllSent(); 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_; std::vector<CallbackType> callbacks_; std::mutex notifier_access_; std::vector<std::tuple<Args...>> tuples_; std::condition_variable notifier_condition_;
Detailed Documentation
Extension to LogReader. Provide write access to the log.
Methods
void ResetPercentage(bool enable_percentage = true)
Reset percentage value and disable it optionally.
void SetPercentage(float value)
Set amount of percentage to defined value. Clamped to range <0,1>
LogWriter& operator+=(const float percentage_increment)
Increment progress-bar value by an amount of percentage.
LogWriter& operator<<(const std::shared_ptr<LogEntry> entry)
Add a log entry to the log. If output stream enabled, print to output stream.
LogWriter& Add(const LogEntry&& entry)
Add an entry to the log. If output stream enabled, print to output stream.
LogWriter& Add(const std::shared_ptr<LogEntry> entry)
Add an entry to the log. If output stream enabled, print to output stream.
template <typename ... Params> LogWriter& AddEntry(Params&&... params)
Add an entry to the log. If output stream enabled, print to output stream.
LogWriter& Inform(const std::string& message, const std::string& caller_name)
Add a Info entry to the log. If output stream enabled, print to output stream.
LogWriter& Warn(const std::string& message, const std::string& caller_name)
Add a Warning entry to the log. If output stream enabled, print to output stream.
LogWriter& Fail(const std::string& message, const std::string& caller_name)
Add a Error entry to the log. If output stream enabled, print to output stream.
LogWriter& Crash(const std::string& message, const std::string& caller_name)
Add a Critical entry to the log. If output stream enabled, print to output stream.
template <class CT> LogWriter& Inform(const std::string& message, const utils::NamedClass<CT>* caller)
Add a Info entry to the log. If output stream enabled, print to output stream. Pass caller to get its name.
template <class CT> LogWriter& Warn(const std::string& message, const utils::NamedClass<CT>* caller)
Add a Warning entry to the log. If output stream enabled, print to output stream. Pass caller to get its name.
template <class CT> LogWriter& Fail(const std::string& message, const utils::NamedClass<CT>* caller)
Add a Error entry to the log. If output stream enabled, print to output stream. Pass caller to get its name.
template <class CT> LogWriter& Crash(const std::string& message, const utils::NamedClass<CT>* caller)
Add a Critical entry to the log. If output stream enabled, print to output stream. Pass caller to get its name.
LogWriter& CopyUnreadEntries(const LogReader& other)
Copy all unread entries from another LogReader.
void StartTimeMeasure(const std::string& measurement_name)
Start time measurement + print to log.
void StopTimeMeasure()
End time measurements + print to log.
bool SaveToFile(const std::string& file_path)
Save all log messages to a file.
bool DisplayUnread(const utils::EnumFlags<utils::LogEntry::Type>& types, const std::function<void(const std::wstring&, const std::wstring&)>& ShowMessageBox = nullptr)
Read all unread messages from log with the selected types and display them supplied message dialog function.