feat(logger): allow construction without explicit terminal / ostream

This commit is contained in:
Marcus Holland-Moritz 2024-08-07 20:15:48 +02:00
parent 93a6979cb6
commit 1dbefd98c1
2 changed files with 9 additions and 1 deletions

View File

@ -101,6 +101,8 @@ struct logger_options {
class stream_logger : public logger {
public:
explicit stream_logger(logger_options const& options = {});
explicit stream_logger(std::ostream& os, logger_options const& options = {});
stream_logger(std::shared_ptr<terminal const> term, std::ostream& os,
logger_options const& options = {});

View File

@ -42,7 +42,7 @@
#include <fmt/format.h>
#include <dwarfs/logger.h>
#include <dwarfs/terminal.h>
#include <dwarfs/terminal_ansi.h>
#include <dwarfs/util.h>
namespace dwarfs {
@ -105,6 +105,12 @@ std::string logger::all_level_names() {
null_logger::null_logger() { set_policy<prod_logger_policy>(); }
stream_logger::stream_logger(logger_options const& options)
: stream_logger(std::cerr, options) {}
stream_logger::stream_logger(std::ostream& os, logger_options const& options)
: stream_logger(std::make_shared<terminal_ansi>(), os, options) {}
stream_logger::stream_logger(std::shared_ptr<terminal const> term,
std::ostream& os, logger_options const& logopts)
: os_(os)