diff --git a/example/example.cpp b/example/example.cpp index 493cbc36..69e24b64 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -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()); + logger2.add_sink(std::make_shared()); + 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++) diff --git a/include/c11log/common_types.h b/include/c11log/common_types.h new file mode 100644 index 00000000..bc25297d --- /dev/null +++ b/include/c11log/common_types.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +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]; +} + diff --git a/include/c11log/logger.h b/include/c11log/logger.h index e68ba25e..40486474 100644 --- a/include/c11log/logger.h +++ b/include/c11log/logger.h @@ -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 + details::line_logger& operator<<(const T& msg) { + return _logger->info() << msg; + } + +private: + c11log::logger* _logger; +}; +}