53 std::string_view category;
54 std::string_view text;
55 std::chrono::system_clock::time_point time;
87 virtual void Write(
const Message& message) = 0;
89 virtual void Flush() = 0;
105 void Write(
const Message& message)
override;
107 void Flush()
override;
122 std::filesystem::path path_;
130 std::string category;
132 std::chrono::system_clock::time_point time;
140 static constexpr size_t kCapacity = 4096;
157 u64
CopySince(u64 after, std::vector<CapturedMessage>& out)
const;
163 mutable std::mutex mutex_;
164 std::deque<CapturedMessage> messages_;
171class ProcessLoggerControl;
182 std::span<const log::LogCategory* const> categories) = 0;
187 virtual void RemoveCategories(std::span<const log::LogCategory* const> categories) = 0;
199 virtual void Flush() = 0;
218 REX_SETTING(std::string, level,
"info",
219 "Lowest level written by a category without its own level",
220 Allowed(
"trace",
"dev",
"debug",
"info",
"warn",
"error",
"critical",
"off"));
221 REX_SETTING(std::string, flush_level,
"warn",
"Lowest level that flushes every sink at once",
222 Allowed(
"trace",
"dev",
"debug",
"info",
"warn",
"error",
"critical",
"off"),
224 REX_SETTING(i32, flush_interval, 1,
"Seconds between flushes",
Range{0, 60}, kStartupOnly);
225 REX_SETTING(
bool, console,
true,
"Write to the console", kStartupOnly);
226 REX_SETTING(
bool, debugger,
true,
"Write to an attached debugger", kStartupOnly);
227 REX_SETTING(
bool, file,
true,
"Write a log file under app.log_root", kStartupOnly);
228 REX_SETTING(std::string, file_name,
"",
"File name, the app name when empty", kStartupOnly);
229 REX_SETTING(i64, folder_budget, 0,
"Bytes of old log files kept, 0 keeps all",
230 Range{0, 9007199254740992.0}, kStartupOnly);
231 REX_SETTING(std::string, pattern,
"%^%Y-%m-%d %H:%M:%S.%e %Q %-10n %j %v%$",
232 "Layout of each line, an spdlog pattern with %Q for the level letter and %j for the "
235 REX_SETTING(
bool, color,
false,
"Color the console", kStartupOnly);
238 std::span<const log::LogCategory* const> categories)
override;
253 friend class ProcessLoggerControl;
256 [[nodiscard]]
Result<void> OpenFile(
const std::filesystem::path& log_root,
257 std::string_view app_name);
260 std::unique_ptr<State> state_;
266#define REX_LOGGER() ::rex::GetLogger()
ScopeGuard AddSink(log::ILogSink &sink) override
void Emit(const log::Message &message) override
friend Logger & GetLogger()
void RemoveCategories(std::span< const log::LogCategory *const > categories) override
Result< void > AddCategories(std::span< const log::LogCategory *const > categories) override
SettingOwner(std::string_view scope)
void Write(const Message &message) override
u64 GetLatestSequence() const
u64 CopySince(u64 after, std::vector< CapturedMessage > &out) const
LogFileSink(std::filesystem::path path, std::ofstream file, LineFormat format)
static Result< std::unique_ptr< LogFileSink > > Open(const std::filesystem::path &path, LineFormat format)
const std::filesystem::path & GetPath() const
Interfaces, factory and module declaration.
#define REX_DECLARE_INTERFACE(Name, version)
Definition module.h:114
Definition log_category.h:29
std::string FormatLine(const Message &message, const LineFormat &format)
Level
Definition log_category.h:32
@ kInfo
Definition log_category.h:36
constexpr std::string_view kColorReset
Definition logger.h:68
TimestampStyle
Definition logger.h:35
@ kElapsed
Definition logger.h:39
@ kClock
Definition logger.h:37
@ kDateTime
Definition logger.h:38
char LevelLetter(Level level)
std::string_view LevelColor(Level level)
std::expected< T, Error > Result
Definition result.h:98
Typed settings and the owners that declare them.
u64 sequence
Definition logger.h:57
Integer types, byte order wrappers and size literals.
Move only function, const propagating pointer and scope guard.