Implemented logging utilities
This commit is contained in:
13
source/log/include/ILogFacility.hpp
Normal file
13
source/log/include/ILogFacility.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <format>
|
||||
#include <string_view>
|
||||
|
||||
namespace ugly {
|
||||
|
||||
class ILogFacility {
|
||||
public:
|
||||
virtual void vlog(std::string_view fmt, std::format_args args) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
24
source/log/include/LogUtils.hpp
Normal file
24
source/log/include/LogUtils.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILogFacility.hpp"
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace ugly {
|
||||
|
||||
class LogAlias {
|
||||
public:
|
||||
ILogFacility *mpLog;
|
||||
|
||||
template<typename ...Args>
|
||||
LogAlias &operator()(std::format_string<Args...> format, Args &&...args) {
|
||||
if(mpLog) {
|
||||
mpLog->vlog(format.get(), std::make_format_args(args...));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
extern LogAlias log;
|
||||
|
||||
}
|
||||
24
source/log/include/TimestampLog.hpp
Normal file
24
source/log/include/TimestampLog.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILogFacility.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <ostream>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
namespace ugly {
|
||||
|
||||
class TimestampLog: virtual public ILogFacility {
|
||||
private:
|
||||
std::ostream &mrOutputStream;
|
||||
std::string mDescription;
|
||||
std::chrono::high_resolution_clock::time_point mStart;
|
||||
|
||||
public:
|
||||
TimestampLog(std::ostream &os, std::string_view description);
|
||||
void vlog(std::string_view fmt, std::format_args args) override;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user