diff --git a/include/caosdb/logging.h b/include/caosdb/logging.h index 0fa4da51c5de7727e8d882d9679b04a4d1bdaa38..73f14cad5ad779dcb2bdb134325ad7397f436edb 100644 --- a/include/caosdb/logging.h +++ b/include/caosdb/logging.h @@ -41,11 +41,11 @@ typedef boost::log::sources::severity_channel_logger_mt<int, std::string> boost_ class logger { public: - static boost_logger_class &get() { return *logger::GetInstance()._logger_instance; } - static void destroy() { + static auto destroy() -> void { auto &instance = logger::GetInstance(); delete instance._logger_instance; } + static auto get() -> boost_logger_class & { return *logger::GetInstance()._logger_instance; } private: logger() { this->_logger_instance = new boost_logger_class(); }; @@ -56,8 +56,6 @@ private: boost_logger_class *_logger_instance; }; -auto inline get_logger() -> boost_logger_class & { return logger::get(); } - /** * This class stores the integer log level. */ @@ -203,17 +201,17 @@ void caosdb_log_trace(const char *channel, const char *msg); } // namespace caosdb::logging #define CAOSDB_LOG_FATAL(Channel) \ - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), Channel, CAOSDB_LOG_LEVEL_FATAL) + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, CAOSDB_LOG_LEVEL_FATAL) #define CAOSDB_LOG_ERROR(Channel) \ - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), Channel, CAOSDB_LOG_LEVEL_ERROR) + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, CAOSDB_LOG_LEVEL_ERROR) #define CAOSDB_LOG_WARN(Channel) \ - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), Channel, CAOSDB_LOG_LEVEL_WARN) + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, CAOSDB_LOG_LEVEL_WARN) #define CAOSDB_LOG_INFO(Channel) \ - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), Channel, CAOSDB_LOG_LEVEL_INFO) + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, CAOSDB_LOG_LEVEL_INFO) #define CAOSDB_LOG_DEBUG(Channel) \ - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), Channel, CAOSDB_LOG_LEVEL_DEBUG) + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, CAOSDB_LOG_LEVEL_DEBUG) #define CAOSDB_LOG_TRACE(Channel) \ - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), Channel, CAOSDB_LOG_LEVEL_TRACE) + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, CAOSDB_LOG_LEVEL_TRACE) #define CAOSDB_LOG_ERROR_AND_RETURN_STATUS(Channel, StatusCode, Message) \ CAOSDB_LOG_ERROR(Channel) << "StatusCode (" << StatusCode << ") " \ diff --git a/src/caosdb/logging.cpp b/src/caosdb/logging.cpp index c684862d17291c328e3a8d7856b82df1eb507001..ddbda4f05a2582ae058f63f7b4c1c8453b9960dd 100644 --- a/src/caosdb/logging.cpp +++ b/src/caosdb/logging.cpp @@ -44,13 +44,8 @@ #include <utility> // for move #include <vector> -void __attribute__((constructor)) startup() { - std::cout << "LOADING CAOSDB" << std::endl; -} -void __attribute__((destructor)) shutdown() { - std::cout << "UNLOADING CAOSDB" << std::endl; - caosdb::logging::logger::destroy(); -} +void __attribute__((constructor)) startup() {} +void __attribute__((destructor)) shutdown() { caosdb::logging::logger::destroy(); } namespace caosdb::logging { @@ -140,7 +135,7 @@ auto initialize_logging_defaults() -> int { } boost::log::init_from_settings(default_settings); - // core->add_global_attribute("TimeStamp", boost::log::attributes::local_clock()); + core->add_global_attribute("TimeStamp", boost::log::attributes::local_clock()); CAOSDB_LOG_DEBUG(logger_name) << "Initialized default settings."; @@ -176,27 +171,27 @@ auto initialize_logging(const LoggingConfiguration &configuration) -> void { } void caosdb_log_fatal(const char *channel, const char *msg) { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), channel, CAOSDB_LOG_LEVEL_FATAL) << msg; + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_FATAL) << msg; } void caosdb_log_error(const char *channel, const char *msg) { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), channel, CAOSDB_LOG_LEVEL_ERROR) << msg; + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_ERROR) << msg; } void caosdb_log_warn(const char *channel, const char *msg) { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), channel, CAOSDB_LOG_LEVEL_WARN) << msg; + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_WARN) << msg; } void caosdb_log_info(const char *channel, const char *msg) { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), channel, CAOSDB_LOG_LEVEL_INFO) << msg; + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_INFO) << msg; } void caosdb_log_debug(const char *channel, const char *msg) { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), channel, CAOSDB_LOG_LEVEL_DEBUG) << msg; + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_DEBUG) << msg; } void caosdb_log_trace(const char *channel, const char *msg) { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::get_logger(), channel, CAOSDB_LOG_LEVEL_TRACE) << msg; + BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, CAOSDB_LOG_LEVEL_TRACE) << msg; } } // namespace caosdb::logging diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 27b6025b6e9534850daea9e01ea58977d6235ba2..6e2559adf6b89881d990148ba306e1ba2d05892b 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -143,16 +143,17 @@ TEST(test_entity, test_append_property) { } TEST(test_entity, entity_copy_constructor) { - ProtoParent parent; - parent.set_description("the parent desc"); - parent.set_id("the parent id"); - parent.set_name("the parent name"); - ProtoProperty property; - property.set_id("the-prop-id"); - property.set_description("the prop-desc"); - property.set_name("the-prop-name"); - property.mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5); - property.mutable_data_type()->mutable_list_data_type()->set_atomic_data_type( + Arena arena; + auto *parent = Arena::CreateMessage<ProtoParent>(&arena); + parent->set_description("the parent desc"); + parent->set_id("the parent id"); + parent->set_name("the parent name"); + auto *property = Arena::CreateMessage<ProtoProperty>(&arena); + property->set_id("the-prop-id"); + property->set_description("the prop-desc"); + property->set_name("the-prop-name"); + property->mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5); + property->mutable_data_type()->mutable_list_data_type()->set_atomic_data_type( ProtoAtomicDataType::ATOMIC_DATA_TYPE_DOUBLE); auto *entity_response = Arena::CreateMessage<EntityResponse>(&arena); entity_response->mutable_entity()->set_id("the-id"); @@ -198,16 +199,17 @@ TEST(test_entity, entity_copy_constructor) { } TEST(test_entity, entity_move_constructor) { - ProtoParent parent; - parent.set_description("the parent desc"); - parent.set_id("the parent id"); - parent.set_name("the parent name"); - ProtoProperty property; - property.set_id("the-prop-id"); - property.set_description("the prop-desc"); - property.set_name("the-prop-name"); - property.mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5); - property.mutable_data_type()->mutable_list_data_type()->set_atomic_data_type( + Arena arena; + auto *parent = Arena::CreateMessage<ProtoParent>(&arena); + parent->set_description("the parent desc"); + parent->set_id("the parent id"); + parent->set_name("the parent name"); + auto *property = Arena::CreateMessage<ProtoProperty>(&arena); + property->set_id("the-prop-id"); + property->set_description("the prop-desc"); + property->set_name("the-prop-name"); + property->mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5); + property->mutable_data_type()->mutable_list_data_type()->set_atomic_data_type( ProtoAtomicDataType::ATOMIC_DATA_TYPE_DOUBLE); auto *entity_response = Arena::CreateMessage<EntityResponse>(&arena); entity_response->mutable_errors()->Add()->set_code(25);