Repo-Init
 
Loading...
Searching...
No Matches
MainLogger Class Reference

#include <Logger.hpp>

Public Member Functions

 MainLogger (const std::string &lokiAddr, const std::string &sentryAddr)
 
 MainLogger (const MainLogger &)=delete
 Copy constructor.
 
 MainLogger (MainLogger &&)=delete
 Move constructor.
 
MainLoggeroperator= (MainLogger)=delete
 Copy assignment operator.
 
MainLoggeroperator= (MainLogger &&)=delete
 Move assignment operator.
 
std::shared_ptr< spdlog::logger > getLogger () const
 
 ~MainLogger ()
 

Private Attributes

std::shared_ptr< spdlog::logger > _mainLogger
 

Detailed Description

Main logger class

Definition at line 8 of file Logger.hpp.

Constructor & Destructor Documentation

◆ MainLogger() [1/3]

MainLogger::MainLogger ( const std::string & lokiAddr,
const std::string & sentryAddr )

Constructs and prepares main logger

Parameters
[in]lokiAddrLoki address
[in]sentryAddrSentry address

Definition at line 19 of file Logger.cpp.

20{
21 spdlog::set_level(spdlog::level::off);
22
23 // Prepare spdlog loggers
24 auto dupFilter = std::make_shared<spdlog::sinks::dup_filter_sink_mt>(std::chrono::seconds(LOG_FILTER_SECS));
25 if (getppid() != 1) // Disable stdout output for systemd
26 {
27 dupFilter->add_sink(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
28 }
29 dupFilter->add_sink(std::make_shared<spdlog::sinks::syslog_sink_mt>(PROJECT_NAME, LOG_USER, 0, false));
30 dupFilter->add_sink(std::make_shared<spdlog::sinks::loki_api_sink_mt>(lokiAddr));
31 dupFilter->add_sink(std::make_shared<spdlog::sinks::sentry_api_sink_mt>(sentryAddr));
32
33 // Register main logger
34 _mainLogger = std::make_shared<spdlog::logger>(PROJECT_NAME, dupFilter);
35
36 spdlog::set_default_logger(_mainLogger);
37 spdlog::flush_every(std::chrono::seconds(LOG_FLUSH_SECS));
38
39#ifdef NDEBUG
40 spdlog::set_level(spdlog::level::warn);
41#else
42 spdlog::set_level(spdlog::level::info);
43#endif
44
45 PRINT_VERSION();
46}
constexpr int LOG_FILTER_SECS
Definition Logger.cpp:15
constexpr int LOG_FLUSH_SECS
Definition Logger.cpp:17
std::shared_ptr< spdlog::logger > _mainLogger
Definition Logger.hpp:10

◆ MainLogger() [2/3]

MainLogger::MainLogger ( const MainLogger & )
delete

Copy constructor.

◆ MainLogger() [3/3]

MainLogger::MainLogger ( MainLogger && )
delete

Move constructor.

◆ ~MainLogger()

MainLogger::~MainLogger ( )

Deconstructs the main logger

Definition at line 48 of file Logger.cpp.

49{
50 spdlog::info("Goodbye!");
51 _mainLogger->flush();
52}

Member Function Documentation

◆ getLogger()

std::shared_ptr< spdlog::logger > MainLogger::getLogger ( ) const
inlinenodiscard

Returns pointer to mainlogger instance

Returns
std::shared_ptr<spdlog::logger> Main logger

Definition at line 36 of file Logger.hpp.

36{ return _mainLogger; }

◆ operator=() [1/2]

MainLogger & MainLogger::operator= ( MainLogger && )
delete

Move assignment operator.

◆ operator=() [2/2]

MainLogger & MainLogger::operator= ( MainLogger )
delete

Copy assignment operator.

Member Data Documentation

◆ _mainLogger

std::shared_ptr<spdlog::logger> MainLogger::_mainLogger
private

Definition at line 10 of file Logger.hpp.


The documentation for this class was generated from the following files: