1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-04-27 18:56:49 +03:00
wsrep-lib/include/wsrep/logger.hpp
Teemu Ollakka 1f6a6db1e9 * Fixes to SST time server state management
* Logging tweaks
* Boolean to tune behavior on exception
2018-06-22 13:03:12 +03:00

92 lines
1.8 KiB
C++

//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#ifndef WSREP_LOGGER_HPP
#define WSREP_LOGGER_HPP
#include "mutex.hpp"
#include "lock.hpp"
#include <iosfwd>
#include <sstream>
namespace wsrep
{
class log
{
public:
enum level
{
debug,
info,
warning,
error
};
static const char* to_c_string(enum level level)
{
switch (level)
{
case debug: return "debug";
case info: return "info";
case warning: return "warning";
case error: return "error";
};
return "unknown";
}
log(enum wsrep::log::level level, const char* prefix = "")
: level_(level)
, prefix_(prefix)
, oss_()
{ }
~log()
{
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
os_ << prefix_ << ": " << oss_.str() << std::endl;
}
template <typename T>
std::ostream& operator<<(const T& val)
{
return (oss_ << val);
}
private:
log(const log&);
log& operator=(const log&);
enum level level_;
const char* prefix_;
std::ostringstream oss_;
static wsrep::mutex& mutex_;
static std::ostream& os_;
};
class log_error : public log
{
public:
log_error()
: log(error) { }
};
class log_warning : public log
{
public:
log_warning()
: log(warning) { }
};
class log_info : public log
{
public:
log_info()
: log(info) { }
};
class log_debug : public log
{
public:
log_debug()
: log(debug) { }
};
}
#endif // WSREP_LOGGER_HPP