39 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 40 #error "Only <final/final.h> can be included directly." 50 #include <final/util/fstring.h> 59 class FLog :
public std::stringbuf
63 using FLogPrint = std::function<void(const std::string&)>;
64 using IOManip = decltype(std::endl<
char, std::char_traits<char>>);
69 Info, Warn, Error, Debug
84 auto operator << (
const T&) ->
FLog&;
85 auto operator << (IOManip) ->
FLog&;
86 auto operator << (LogLevel) ->
FLog&;
88 virtual auto getClassName()
const ->
FString;
89 virtual void info (
const std::string&) = 0;
90 virtual void warn (
const std::string&) = 0;
91 virtual void error (
const std::string&) = 0;
92 virtual void debug (
const std::string&) = 0;
93 virtual void flush() = 0;
94 virtual void setOutputStream (
const std::ostream&) = 0;
95 virtual void setLineEnding (LineEnding) = 0;
96 virtual void enableTimestamp() = 0;
97 virtual void disableTimestamp() = 0;
100 auto sync() ->
int override;
101 auto getLevel()
const ->
const LogLevel&;
102 auto setLevel() -> LogLevel&;
103 auto getEnding()
const ->
const LineEnding&;
104 auto setEnding() -> LineEnding&;
108 LogLevel level{LogLevel::Info};
109 LineEnding end_of_line{LineEnding::CRLF};
110 FLogPrint current_log{ [
this] (
const auto& s) { info(s); } };
111 std::mutex current_log_mutex{};
112 std::mutex stream_mutex{};
113 std::ostream stream{
this};
116 friend auto operator << (std::ostream&, LogLevel) -> std::ostream&;
121 void handleOutOfRangeError (
const std::out_of_range& ex);
125 template <
typename T>
126 inline auto FLog::operator << (
const T& s) ->
FLog&
128 std::lock_guard<std::mutex> lock_guard(stream_mutex);
134 inline auto FLog::operator << (IOManip pf) ->
FLog&
136 std::lock_guard<std::mutex> lock_guard(stream_mutex);
142 inline auto FLog::getClassName()
const ->
FString 148 inline auto FLog::getLevel()
const ->
const LogLevel&
154 inline auto FLog::setLevel() -> LogLevel&
160 inline auto FLog::getEnding()
const ->
const LineEnding&
166 inline auto FLog::setEnding() -> LineEnding&
Definition: class_template.cpp:25