Skip to content
Snippets Groups Projects

F grpc f acm

Merged Timm Fitschen requested to merge f-grpc-f-acm into dev
+ 84
21
@@ -25,25 +25,86 @@
#include <boost/log/attributes/clock.hpp>
#include <boost/log/core/core.hpp> // for core
#include <boost/log/core/record.hpp>
#include <boost/log/detail/attachable_sstream_buf.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <boost/move/utility_core.hpp> // for move
#include <boost/multi_index/detail/bidir_node_iterator.hpp>
#include <boost/operators.hpp>
#include <boost/preprocessor/seq/limits/enum_256.hpp>
#include <boost/preprocessor/seq/limits/size_256.hpp>
#include <boost/property_tree/detail/exception_implementation.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/tuple/detail/tuple_basic.hpp> // for get
#include <cstdint> // for uint64_t
#include <memory>
#include <ostream> // for ostream
#include <sstream>
#include <string>
#include <utility> // for move
#include <vector>
namespace caosdb::logging {
using boost_logger_class = boost::log::sources::severity_channel_logger_mt<int, std::string>;
class logger {
public:
static auto get() -> boost_logger_class & { return logger::GetInstance()._logger_instance; }
private:
static logger &GetInstance() {
static logger instance;
return instance;
}
boost_logger_class _logger_instance;
};
LoggerOutputStream::LoggerOutputStream(std::string channel, int level)
: channel(std::move(channel)), level(level) {}
auto LoggerOutputStream::operator<<(std::streambuf *msg) -> LoggerOutputStream & {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg;
return *this;
}
auto LoggerOutputStream::operator<<(int msg) -> LoggerOutputStream & {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg;
return *this;
}
auto LoggerOutputStream::operator<<(int64_t msg) -> LoggerOutputStream & {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg;
return *this;
}
auto LoggerOutputStream::operator<<(uint64_t msg) -> LoggerOutputStream & {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg;
return *this;
}
auto LoggerOutputStream::operator<<(const char *msg) -> LoggerOutputStream & {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg;
return *this;
}
auto LoggerOutputStream::operator<<(const std::string &msg) -> LoggerOutputStream & {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg;
return *this;
}
auto LoggerOutputStream::operator<<(void *msg) -> LoggerOutputStream & {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg;
return *this;
}
LoggingConfiguration::LoggingConfiguration(int level) : LevelConfiguration(level) {}
@@ -61,13 +122,14 @@ SinkConfiguration::SinkConfiguration(std::string name, int level)
[[nodiscard]] auto SinkConfiguration::GetName() const -> const std::string & { return this->name; }
auto SinkConfiguration::Configure(boost::log::settings &settings) const -> void {
CAOSDB_LOG_TRACE(logger_name) << "Enter SinkConfiguration::Configure(&settings)";
auto SinkConfiguration::Configure(void *settings) const -> void {
CAOSDB_LOG_TRACE(logger_name) << "Enter SinkConfiguration::Configure(*settings)";
auto sink = "Sinks." + GetName();
settings[sink]["Destination"] = GetDestination();
settings[sink]["Filter"] = "%Severity% >= " + std::to_string(GetLevel());
settings[sink]["AutoFlush"] = true;
settings[sink]["Format"] = "[%TimeStamp%][%Severity%] %Channel% - %Message%";
auto *boost_settings = static_cast<boost::log::settings *>(settings);
(*boost_settings)[sink]["Destination"] = GetDestination();
(*boost_settings)[sink]["Filter"] = "%Severity% >= " + std::to_string(GetLevel());
(*boost_settings)[sink]["AutoFlush"] = true;
(*boost_settings)[sink]["Format"] = "[%TimeStamp%][%Severity%] %Channel% - %Message%";
}
ConsoleSinkConfiguration::ConsoleSinkConfiguration(const std::string &name, int level)
@@ -78,8 +140,8 @@ ConsoleSinkConfiguration::ConsoleSinkConfiguration(const std::string &name, int
return this->destination;
}
auto ConsoleSinkConfiguration::Configure(boost::log::settings &settings) const -> void {
CAOSDB_LOG_TRACE(logger_name) << "Enter ConsoleSinkConfiguration::Configure(&settings)";
auto ConsoleSinkConfiguration::Configure(void *settings) const -> void {
CAOSDB_LOG_TRACE(logger_name) << "Enter ConsoleSinkConfiguration::Configure(*settings)";
sink_configuration::Configure(settings);
}
@@ -95,10 +157,11 @@ auto FileSinkConfiguration::SetDirectory(const std::string &directory) -> void {
this->directory = std::string(directory);
}
auto FileSinkConfiguration::Configure(boost::log::settings &settings) const -> void {
CAOSDB_LOG_TRACE(logger_name) << "Enter FileSinkConfiguration::Configure(&settings)";
auto FileSinkConfiguration::Configure(void *settings) const -> void {
CAOSDB_LOG_TRACE(logger_name) << "Enter FileSinkConfiguration::Configure(*settings)";
sink_configuration::Configure(settings);
settings["Sink." + GetName() + ".Target"] = this->directory;
auto *boost_settings = static_cast<boost::log::settings *>(settings);
(*boost_settings)["Sink." + GetName() + ".Target"] = this->directory;
}
SyslogSinkConfiguration::SyslogSinkConfiguration(const std::string &name, int level)
@@ -127,7 +190,7 @@ auto initialize_logging_defaults() -> int {
default_settings["Core.DisableLogging"] = false;
for (const auto &sink : default_sinks) {
sink->Configure(default_settings);
sink->Configure(&default_settings);
}
boost::log::init_from_settings(default_settings);
@@ -158,7 +221,7 @@ auto initialize_logging(const LoggingConfiguration &configuration) -> void {
new_settings["Core.DisableLogging"] = false;
for (const auto &sink : configuration.GetSinks()) {
sink->Configure(new_settings);
sink->Configure(&new_settings);
}
boost::log::init_from_settings(new_settings);
@@ -167,27 +230,27 @@ auto initialize_logging(const LoggingConfiguration &configuration) -> void {
}
void caosdb_log_fatal(const char *channel, const char *msg) {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_FATAL) << msg;
LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_FATAL) << msg;
}
void caosdb_log_error(const char *channel, const char *msg) {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_ERROR) << msg;
LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_ERROR) << msg;
}
void caosdb_log_warn(const char *channel, const char *msg) {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_WARN) << msg;
LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_WARN) << msg;
}
void caosdb_log_info(const char *channel, const char *msg) {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_INFO) << msg;
LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_INFO) << msg;
}
void caosdb_log_debug(const char *channel, const char *msg) {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_DEBUG) << msg;
LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_DEBUG) << msg;
}
void caosdb_log_trace(const char *channel, const char *msg) {
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_TRACE) << msg;
LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_TRACE) << msg;
}
} // namespace caosdb::logging
Loading