common_types.h

This commit is contained in:
gabime 2014-03-02 15:59:18 +02:00
parent 3816517e54
commit b396ff85a7
3 changed files with 51 additions and 0 deletions

View File

@ -58,7 +58,11 @@ int main(int argc, char* argv[])
auto &logger2 = c11log::get_logger("logger2");
//logger2.add_sink(fsink2);
logger2.add_sink(std::make_shared<sinks::null_sink>());
logger2.add_sink(std::make_shared<sinks::stdout_sink>());
info_logger info(&logger2);
info << "Hello info logger" << "!!";
return 0;
auto start = system_clock::now();
const unsigned int howmany = 10000000;
for(unsigned int i = 0; i < howmany ; i++)

View File

@ -0,0 +1,27 @@
#pragma once
#include <chrono>
namespace c11log {
typedef std::chrono::system_clock log_clock;
namespace level {
typedef enum {
DEBUG,
INFO,
WARNING,
ERROR,
FATAL,
NONE = 99
} level_enum;
const char* to_str(level_enum l);
}
}
static const char* level_names[] { "Debug", "Info", "Warning", "Error", "Fatal" };
inline const char* c11log::level::to_str(c11log::level::level_enum l)
{
return level_names[l];
}

View File

@ -69,8 +69,14 @@ private:
};
logger& get_logger(const std::string& name);
}
//
// Logger inline impl
//
@ -163,3 +169,17 @@ inline c11log::logger& c11log::get_logger(const std::string& name)
return *(c11log::details::factory::instance().get_logger(name));
}
namespace c11log {
class info_logger {
public:
info_logger (c11log::logger* logger):_logger(logger) {}
template<class T>
details::line_logger& operator<<(const T& msg) {
return _logger->info() << msg;
}
private:
c11log::logger* _logger;
};
}