Skip to content
Snippets Groups Projects
Verified Commit 1aba35eb authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: logging

parent 1db4cc02
No related branches found
No related tags found
1 merge request!3Better Error Handling and Logging
Pipeline #10838 failed
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
......@@ -23,38 +23,16 @@
#ifndef CAOSDB_LOGGING_H
#define CAOSDB_LOGGING_H
#include "caosdb/log_level.h"
#include <cstddef>
#include <string>
#include <iostream>
#include <vector>
#include <memory>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/log/utility/setup/formatter_parser.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#define CAOSDB_LOG_FATAL(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_FATAL)
#define CAOSDB_LOG_ERROR(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_ERROR)
#define CAOSDB_LOG_WARN(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_WARN)
#define CAOSDB_LOG_INFO(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_INFO)
#define CAOSDB_LOG_DEBUG(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_DEBUG)
#define CAOSDB_LOG_TRACE(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_TRACE)
#include "caosdb/log_level.h" // for CAOSDB_LOG_...
#include "boost/log/sources/global_logger_storage.hpp" // for BOOST_LOG_I...
#include "boost/log/sources/record_ostream.hpp" // IWYU pragma: keep
#include "boost/log/sources/severity_channel_logger.hpp" // for BOOST_LOG_C...
#include "boost/log/utility/setup/settings.hpp" // for settings
#include "boost/smart_ptr/intrusive_ptr.hpp" // for intrusive_ptr
#include "boost/smart_ptr/intrusive_ref_counter.hpp" // for intrusive_p...
#include <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector
namespace caosdb::logging {
......@@ -62,6 +40,7 @@ const std::string logger_name = "caosdb::logging";
typedef boost::log::sources::severity_channel_logger<int, std::string>
boost_logger_class;
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class)
class LevelConfiguration {
......@@ -156,5 +135,50 @@ private:
const std::string destination = "Syslog";
};
/**
* Convenience function for the c-interface.
*/
void caosdb_log_fatal(const char *channel, const char *msg);
/**
* Convenience function for the c-interface.
*/
void caosdb_log_error(const char *channel, const char *msg);
/**
* Convenience function for the c-interface.
*/
void caosdb_log_warn(const char *channel, const char *msg);
/**
* Convenience function for the c-interface.
*/
void caosdb_log_info(const char *channel, const char *msg);
/**
* Convenience function for the c-interface.
*/
void caosdb_log_debug(const char *channel, const char *msg);
/**
* Convenience function for the c-interface.
*/
void caosdb_log_trace(const char *channel, const char *msg);
} // namespace caosdb::logging
#define CAOSDB_LOG_FATAL(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_FATAL)
#define CAOSDB_LOG_ERROR(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_ERROR)
#define CAOSDB_LOG_WARN(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_WARN)
#define CAOSDB_LOG_INFO(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_INFO)
#define CAOSDB_LOG_DEBUG(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_DEBUG)
#define CAOSDB_LOG_TRACE(Channel) \
BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), Channel, \
CAOSDB_LOG_LEVEL_TRACE)
#endif
......@@ -19,18 +19,27 @@
*
*/
#include "caosdb/logging.h"
#include "boost/core/swap.hpp" // for swap
#include "boost/iterator/iterator_facade.hpp"
#include "boost/log/attributes/clock.hpp"
#include "boost/log/core/core.hpp" // for core
#include "boost/log/core/record.hpp"
#include "boost/log/sources/record_ostream.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/shared_ptr.hpp"
#include "boost/tuple/detail/tuple_basic.hpp" // for get
#include "caosdb/log_level.h"
#include <boost/log/sources/global_logger_storage.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/formatter_parser.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <cstddef>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <utility> // for move
#include <vector>
namespace caosdb::logging {
......@@ -152,4 +161,40 @@ auto initialize_logging(const LoggingConfiguration &configuration) -> void {
CAOSDB_LOG_DEBUG(logger_name) << "Initialized logging with custom settings.";
}
void caosdb_log_fatal(const char *channel, const char *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::logger::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;
}
void caosdb_log_info(const char *channel, const char *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::logger::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;
}
} // namespace caosdb::logging
......@@ -8,9 +8,12 @@
#include <exception>
#include <iostream>
#include <stdio.h>
#include <string.h>
extern "C" {
#define CCAOSDB_LOGGER_NAME "ccaosd"
/*
* Macro for wrapping every function into a try-catch clause. If an exception
* occurs, the given StatusCode is being returned.
......@@ -20,7 +23,7 @@ extern "C" {
try { \
body \
} catch (const std::exception &exc) { \
CAOSDB_LOG_FATAL("ccaosdb") << "Exception: " << exc.what(); \
caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what()); \
return caosdb::StatusCode::code; \
} \
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment