Added some comments

This commit is contained in:
2025-07-31 02:09:45 -04:00
parent 15220aa3b7
commit d36115c841
7 changed files with 73 additions and 4 deletions

View File

@@ -5,9 +5,17 @@
namespace ugly {
/**
* \brief Interface for a generic log-like object.
*/
class ILogFacility {
public:
~ILogFacility() = default;
/**
* \brief Put a message into the log, \c std::vformat -style.
* \param fmt Format string.
* \param args Format arguments.
*/
virtual void vlog(std::string_view fmt, std::format_args args) = 0;
};

View File

@@ -6,6 +6,9 @@
namespace ugly {
/**
* \brief Provides \c std::format -style variadic template functions for \ref ILogFacility.
*/
class LogAlias {
public:
ILogFacility *mpLog;
@@ -19,6 +22,11 @@ public:
}
};
/**
* \brief Globally-shared log.
*
* Should be assigned to by the user, defaults to a null log.
*/
extern LogAlias log;
}

View File

@@ -10,6 +10,9 @@
namespace ugly {
/**
* \brief Log that automatically annotates messages with time and name.
*/
class TimestampLog: virtual public ILogFacility {
private:
std::chrono::high_resolution_clock::time_point mStartTime;
@@ -17,6 +20,10 @@ private:
std::string mDescription;
public:
/**
* \param description Name of the log to appear in the messages.
* \param os Output stream.
*/
TimestampLog(std::string_view description, std::ostream &os);
void vlog(std::string_view fmt, std::format_args args) override;
};

View File

@@ -12,6 +12,7 @@ TimestampLog::TimestampLog(std::string_view description, std::ostream &os):
void TimestampLog::vlog(std::string_view fmt, std::format_args args) {
// Format message as "[123.4567] Name: User Message\n"
using namespace std::chrono;
auto now = high_resolution_clock::now();
auto timestamp = duration_cast<duration<float>>(now - mStartTime).count();