74 lines
1.5 KiB
C++
Executable File
74 lines
1.5 KiB
C++
Executable File
#pragma once
|
|
|
|
#include "lib/utils/bts_no_copy.h"
|
|
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <memory>
|
|
|
|
namespace bts {
|
|
namespace config {
|
|
namespace internal {
|
|
|
|
class IConfigLog
|
|
{
|
|
public:
|
|
virtual void info(const std::string& msg) = 0;
|
|
virtual void error(const std::string& msg) = 0;
|
|
virtual void warning(const std::string& msg) = 0;
|
|
virtual ~IConfigLog() { }
|
|
};
|
|
|
|
// A back door though the logging system
|
|
// To allow config diagnostic logging
|
|
class ConfigLog : public IConfigLog
|
|
{
|
|
public:
|
|
ConfigLog();
|
|
~ConfigLog();
|
|
|
|
void info(const std::string& msg);
|
|
void error(const std::string& msg);
|
|
void warning(const std::string& msg);
|
|
|
|
bool print_errors() const ;
|
|
void set_print_errors(bool value) ;
|
|
|
|
private:
|
|
void start();
|
|
struct PImpl;
|
|
std::unique_ptr<PImpl> me;
|
|
};
|
|
|
|
// Log aggregator aggregates Info and warning messages into one string
|
|
// but passes error message through to the log immediately
|
|
class LogAggregator : public IConfigLog
|
|
{
|
|
public:
|
|
LogAggregator(IConfigLog& real_log);
|
|
void info(const std::string&);
|
|
void error(const std::string&);
|
|
void warning(const std::string&);
|
|
|
|
std::string text();
|
|
|
|
private:
|
|
IConfigLog& _log;
|
|
std::ostringstream _buffer;
|
|
};
|
|
|
|
class ErrorsOnlyLog : public IConfigLog
|
|
{
|
|
public:
|
|
ErrorsOnlyLog(IConfigLog& log) : _log(log) {}
|
|
~ErrorsOnlyLog() {}
|
|
void info(const std::string&) {}
|
|
void error(const std::string& msg) { _log.error(msg); }
|
|
void warning(const std::string& msg) { _log.error(msg); }
|
|
private:
|
|
IConfigLog& _log;
|
|
};
|
|
|
|
}}}//namespace
|
|
|