Skip to content

Commit

Permalink
Set default spdlog logger to log to syslog and stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed Jul 25, 2024
1 parent 7c4e4d0 commit a8968ab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lib_src = [
'src/uenv/env.cpp',
'src/uenv/envvars.cpp',
'src/uenv/lex.cpp',
'src/uenv/log.cpp',
'src/uenv/meta.cpp',
'src/uenv/parse.cpp',
'src/util/strings.cpp',
Expand Down
2 changes: 2 additions & 0 deletions src/cli/uenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <fmt/core.h>
#include <spdlog/spdlog.h>

#include <uenv/log.h>

#include "start.h"
#include "uenv.h"

Expand Down
21 changes: 21 additions & 0 deletions src/uenv/log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <memory>

#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/syslog_sink.h"
#include <spdlog/spdlog.h>

#include "log.h"

namespace uenv {
void init_log() {
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::warn);

auto syslog_sink = std::make_shared<spdlog::sinks::syslog_sink_mt>(
"uenv", LOG_PID, 0, false);
syslog_sink->set_level(spdlog::level::trace);

spdlog::set_default_logger(std::make_shared<spdlog::logger>(
"uenv", spdlog::sinks_init_list({console_sink, syslog_sink})));
}
} // namespace uenv
3 changes: 3 additions & 0 deletions src/uenv/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace uenv {
void init_log();
}

0 comments on commit a8968ab

Please sign in to comment.