Skip to content
Snippets Groups Projects

Better Error Handling and Logging

3 files
+ 114
42
Compare changes
  • Side-by-side
  • Inline

Files

+ 56
32
@@ -23,38 +23,16 @@
@@ -23,38 +23,16 @@
#ifndef CAOSDB_LOGGING_H
#ifndef CAOSDB_LOGGING_H
#define CAOSDB_LOGGING_H
#define CAOSDB_LOGGING_H
#include "caosdb/log_level.h"
#include "caosdb/log_level.h" // for CAOSDB_LOG_...
#include <cstddef>
#include "boost/log/sources/global_logger_storage.hpp" // for BOOST_LOG_I...
#include <string>
#include "boost/log/sources/record_ostream.hpp" // IWYU pragma: keep
#include <iostream>
#include "boost/log/sources/severity_channel_logger.hpp" // for BOOST_LOG_C...
#include <vector>
#include "boost/log/utility/setup/settings.hpp" // for settings
#include <memory>
#include "boost/smart_ptr/intrusive_ptr.hpp" // for intrusive_ptr
#include <boost/log/sources/severity_channel_logger.hpp>
#include "boost/smart_ptr/intrusive_ref_counter.hpp" // for intrusive_p...
#include <boost/log/sources/record_ostream.hpp>
#include <memory> // for shared_ptr
#include <boost/log/utility/setup/common_attributes.hpp>
#include <string> // for string
#include <boost/log/utility/setup/settings.hpp>
#include <vector> // for vector
#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)
namespace caosdb::logging {
namespace caosdb::logging {
@@ -62,6 +40,7 @@ const std::string logger_name = "caosdb::logging";
@@ -62,6 +40,7 @@ const std::string logger_name = "caosdb::logging";
typedef boost::log::sources::severity_channel_logger<int, std::string>
typedef boost::log::sources::severity_channel_logger<int, std::string>
boost_logger_class;
boost_logger_class;
 
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class)
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class)
class LevelConfiguration {
class LevelConfiguration {
@@ -156,5 +135,50 @@ private:
@@ -156,5 +135,50 @@ private:
const std::string destination = "Syslog";
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
} // 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
#endif
Loading