Skip to content
Snippets Groups Projects

Better Error Handling and Logging

Merged Timm Fitschen requested to merge dev into main
All threads resolved!
3 files
+ 114
42
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 56
32
@@ -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
Loading