#pragma once #include #include #include #include #include #include #include #include #include "centiseconds.h" #include #include "enumTools.h" enum class LogLevel { Trace, Debug, Info, Warning, Error, Fatal, EndSentinel }; template<> const std::string& getEnumTypeName(); template<> const std::vector>& getEnumMembers(); std::ostream& operator<<(std::ostream& stream, LogLevel value); std::istream& operator>>(std::istream& stream, LogLevel& value); using LoggerType = boost::log::sources::severity_logger_mt; BOOST_LOG_GLOBAL_LOGGER(globalLogger, LoggerType) #define LOG(level) \ BOOST_LOG_STREAM_WITH_PARAMS(globalLogger::get(), (::boost::log::keywords::severity = level)) #define LOG_TRACE LOG(LogLevel::Trace) #define LOG_DEBUG LOG(LogLevel::Debug) #define LOG_INFO LOG(LogLevel::Info) #define LOG_WARNING LOG(LogLevel::Warning) #define LOG_ERROR LOG(LogLevel::Error) #define LOG_FATAL LOG(LogLevel::Fatal) class PausableBackendAdapter : public boost::log::sinks::basic_formatted_sink_backend { public: PausableBackendAdapter(boost::shared_ptr backend); ~PausableBackendAdapter(); void consume(const boost::log::record_view& recordView, const std::string message); void pause(); void resume(); private: boost::shared_ptr backend; std::vector> buffer; std::mutex mutex; bool isPaused = false; }; boost::shared_ptr addPausableStderrSink(LogLevel minLogLevel); void addFileSink(const boost::filesystem::path& logFilePath, LogLevel minLogLevel); void logTimedEvent(const std::string& eventName, centiseconds start, centiseconds end, const std::string& value);