Utilities
Utilities header only library
utils::LogWriter Class Reference

Extension to LogReader. Provide write access to the log. More...

Inheritance diagram for utils::LogWriter:
[legend]

Public Member Functions

 LogWriter (const LogWriter &)=delete
 
LogWriter & operator= (const LogWriter &)=delete
 
 LogWriter (utils::LogWriter &&)=delete
 
LogWriter & operator= (utils::LogWriter &&)=delete
 
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.
 
- Public Member Functions inherited from utils::LogReader
 LogReader (const LogReader &)=delete
 
LogReader & operator= (const LogReader &)=delete
 
 LogReader (LogReader &&)=delete
 
LogReader & operator= (LogReader &&)=delete
 
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.
 
- Public Member Functions inherited from utils::DelegatedNotifier< Args >
virtual void Notify (Args... args) override
 Notify does not execute all notifications - it merely collects the arguments and allows the Owner to execute them when it pleases.
 
virtual void SendAllNotifications ()
 Send all collected notifications at this moment.
 
virtual void WaitUntilAllSent ()
 Wait until all notifications are sent.
 
- Public Member Functions inherited from utils::Notifier< Args... >
void AddCallback (CallbackType callback)
 Add a single callback function.
 
bool HasCallback () const
 Returns whether it has any callback registered.
 

Additional Inherited Members

- Public Types inherited from utils::Notifier< Args... >
using CallbackType = std::function< void(Args...)>
 The callback is a void function taking the variadic templated arguments of the Notifier class.
 
- Protected Attributes inherited from utils::LogReader
std::ostream * output_stream_ = nullptr
 
ProgressPercentage percentage_
 
std::mutex percentage_access_
 
std::vector< std::shared_ptr< LogEntry > > log_entries_
 Saved log entries.
 
std::mutex log_access_
 mutex to ensure thread safety of the Log.
 
- Protected Attributes inherited from utils::DelegatedNotifier< Args >
std::vector< std::tuple< Args... > > tuples_
 The collected arguments to be executed on the next execution loop call.
 
std::condition_variable notifier_condition_
 Condition variable to trigger rechecking conditions.
 
- Protected Attributes inherited from utils::Notifier< Args... >
std::vector< CallbackType > callbacks_
 The callbacks.
 
std::mutex notifier_access_
 mutex to ensure thread safety.
 

Detailed Description

Extension to LogReader. Provide write access to the log.