log: allow setting the default_sink
This commit is contained in:
parent
67ea686753
commit
7a5fa7fa2d
@ -12,6 +12,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
// Windows.h or one of its friends defines a macro 'ERROR'. Screw Microsoft.
|
||||
#ifdef ERROR
|
||||
#undef ERROR
|
||||
#endif
|
||||
|
||||
namespace cruft::log {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
24
log/log.cpp
24
log/log.cpp
@ -14,6 +14,7 @@
|
||||
|
||||
#include "sink/console.hpp"
|
||||
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@ -42,11 +43,30 @@ cruft::log::needs_break (level_t level)
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static std::once_flag s_sink_init;
|
||||
static std::unique_ptr<cruft::log::sink::base> s_default_sink;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
cruft::log::sink::base&
|
||||
cruft::log::default_sink (std::unique_ptr<sink::base> value)
|
||||
{
|
||||
s_default_sink = std::move (value);
|
||||
return *s_default_sink;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
cruft::log::sink::base&
|
||||
cruft::log::default_sink ()
|
||||
{
|
||||
static sink::console s_default_sink (PACKAGE_NAME);
|
||||
return s_default_sink;
|
||||
std::call_once (s_sink_init, [&] () {
|
||||
default_sink (
|
||||
std::make_unique<sink::console> (PACKAGE_NAME)
|
||||
);
|
||||
});
|
||||
|
||||
return *s_default_sink;
|
||||
}
|
||||
|
||||
|
||||
|
10
log/log.hpp
10
log/log.hpp
@ -13,19 +13,17 @@
|
||||
#include "sink/base.hpp"
|
||||
#include "../format.hpp"
|
||||
|
||||
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// Windows.h or one of its friends defines a macro 'ERROR'. Screw Microsoft.
|
||||
#ifdef ERROR
|
||||
#undef ERROR
|
||||
#endif
|
||||
|
||||
namespace cruft::log {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
sink::base& default_sink (void);
|
||||
sink::base& default_sink (std::unique_ptr<sink::base>);
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void write (level_t, std::string const &msg);
|
||||
void write (level_t, char const *msg);
|
||||
void write (level_t, std::string_view msg);
|
||||
|
Loading…
Reference in New Issue
Block a user