30#ifndef NUMCPP_NO_USE_BOOST
38#include "boost/core/null_deleter.hpp"
39#include "boost/log/attributes.hpp"
40#include "boost/log/core/core.hpp"
41#include "boost/log/expressions.hpp"
42#include "boost/log/expressions/formatters/date_time.hpp"
43#include "boost/log/sinks/sync_frontend.hpp"
44#include "boost/log/sinks/text_ostream_backend.hpp"
45#include "boost/log/sources/global_logger_storage.hpp"
46#include "boost/log/sources/severity_logger.hpp"
47#include "boost/log/support/date_time.hpp"
48#include "boost/log/trivial.hpp"
49#include "boost/log/utility/manipulators/add_value.hpp"
50#include "boost/log/utility/setup/common_attributes.hpp"
51#include "boost/make_shared.hpp"
52#include "boost/shared_ptr.hpp"
59 BOOST_LOG_GLOBAL_LOGGER(fileLogger, boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level>)
64 BOOST_LOG_ATTRIBUTE_KEYWORD(lineId,
"LineID", uint32_t)
65 BOOST_LOG_ATTRIBUTE_KEYWORD(timestamp,
"TimeStamp", boost::posix_time::ptime)
66 BOOST_LOG_ATTRIBUTE_KEYWORD(severity,
"Severity", boost::log::trivial::severity_level)
67 BOOST_LOG_ATTRIBUTE_KEYWORD(filename,
"Filename", std::string)
68 BOOST_LOG_ATTRIBUTE_KEYWORD(functionName,
"FunctionName", std::string)
69 BOOST_LOG_ATTRIBUTE_KEYWORD(lineNumber,
"LineNumber", uint32_t)
80 using text_sink = boost::log::sinks::synchronous_sink<boost::log::sinks::text_ostream_backend>;
86 inline boost::shared_ptr<text_sink>
sinkFile{};
94 constexpr auto counterWidth = 7;
95 boost::log::formatter formatter =
96 boost::log::expressions::stream
97 << std::setw(counterWidth) << std::setfill(
'0') << lineId << std::setfill(
' ') <<
" ["
98 << boost::log::expressions::format_date_time(timestamp,
"%Y-%m-%d %H:%M:%S.%f") <<
"] "
99 <<
"[" << boost::log::trivial::severity <<
"] "
100 <<
"[" << filename <<
":" << functionName <<
"():" << lineNumber <<
"] "
101 << boost::log::expressions::smessage;
112 boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> logger;
115 logger.add_attribute(
"LineID", boost::log::attributes::counter<uint32_t>(1));
116 logger.add_attribute(
"TimeStamp", boost::log::attributes::local_clock());
122 boost::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()));
151 const auto errorCode = [&]
153 auto error = std::error_code{};
154 std::filesystem::create_directories(logFileName.parent_path(), error);
159 auto ss = std::stringstream{};
160 ss <<
"Failed to create " << logFileName <<
" -- " << errorCode.message();
161 throw std::runtime_error{ ss.str() };
168 detail::sinkFile->locked_backend()->add_stream(boost::make_shared<std::ofstream>(logFileName));
188 inline void setLogLevel(boost::log::trivial::severity_level level)
200#define BOOST_LOGGER(severity) \
201 BOOST_LOG_SEV(nc::logger::fileLogger::get(), boost::log::trivial::severity) \
202 << boost::log::add_value("Filename", std::filesystem::path(__FILE__).filename().stem().string()) \
203 << boost::log::add_value("FunctionName", __FUNCTION__) \
204 << boost::log::add_value("LineNumber", uint32_t{ __LINE__ })
208#define LOG_TRACE BOOST_LOGGER(trace)
210#define LOG_DEBUG BOOST_LOGGER(debug)
212#define LOG_INFO BOOST_LOGGER(info)
214#define LOG_WARNING BOOST_LOGGER(warning)
216#define LOG_ERROR BOOST_LOGGER(error)
218#define LOG_FATAL BOOST_LOGGER(fatal)
constexpr boost::log::trivial::severity_level INIT_LOGLEVEL
Definition: Logger.hpp:74
boost::shared_ptr< text_sink > sinkConsole
local variables to hold the sink pointers
Definition: Logger.hpp:85
boost::shared_ptr< text_sink > sinkFile
Definition: Logger.hpp:86
boost::log::formatter createOutputFormat()
function to define the format of the output
Definition: Logger.hpp:91
boost::log::sinks::synchronous_sink< boost::log::sinks::text_ostream_backend > text_sink
Definition: Logger.hpp:80
constexpr char OUTPUT_LOG_FILE_EXT[]
Definition: Logger.hpp:77
Definition: BinaryLogger.hpp:45
BOOST_LOG_GLOBAL_LOGGER_INIT(fileLogger, boost::log::sources::severity_logger_mt)
Global intializer and constructor for the global logger Sets the initial sink to console backend and ...
Definition: Logger.hpp:110
void addOutputFileLog(std::filesystem::path logFileName)
Function to add the name of the output log file.
Definition: Logger.hpp:146
void setLogLevel(boost::log::trivial::severity_level level)
Function to set the severity level to report back to console and log file.
Definition: Logger.hpp:188
dtype trace(const NdArray< dtype > &inArray, int16 inOffset=0, Axis inAxis=Axis::ROW) noexcept
Definition: trace.hpp:47