log: choose sink based on LOG_SINK
This commit is contained in:
parent
c481a7cf38
commit
8961f097cd
21
log/log.cpp
21
log/log.cpp
@ -13,7 +13,9 @@
|
|||||||
#include "../string.hpp"
|
#include "../string.hpp"
|
||||||
|
|
||||||
#include "sink/console.hpp"
|
#include "sink/console.hpp"
|
||||||
|
#include "sink/ostream.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -63,9 +65,28 @@ cruft::log::sink::base&
|
|||||||
cruft::log::default_sink ()
|
cruft::log::default_sink ()
|
||||||
{
|
{
|
||||||
if (unlikely (!s_sink_init)) {
|
if (unlikely (!s_sink_init)) {
|
||||||
|
static char const *DEFAULT_SINK = "CONSOLE";
|
||||||
|
char const *log_sink = getenv ("CRUFT_LOG_SINK") ?: DEFAULT_SINK;
|
||||||
|
|
||||||
|
if (!strcmp (log_sink, "FILE")) {
|
||||||
|
char const *log_path = getenv ("CRUFT_LOG_PATH");
|
||||||
|
default_sink (
|
||||||
|
std::make_unique<sink::ostream> (
|
||||||
|
PACKAGE_NAME,
|
||||||
|
log_path
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (strcmp (log_sink, "CONSOLE")) {
|
||||||
default_sink (
|
default_sink (
|
||||||
std::make_unique<sink::console> (PACKAGE_NAME)
|
std::make_unique<sink::console> (PACKAGE_NAME)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
std::clog << "Unknown logging sink. Falling back to console.\n";
|
||||||
|
default_sink (
|
||||||
|
std::make_unique<sink::console> (PACKAGE_NAME)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
s_sink_init = true;
|
s_sink_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user