Add scoped_logger from waif

This commit is contained in:
Danny Robson 2013-03-05 21:38:51 +11:00
parent 886a36ad5c
commit 011ac70a9d
2 changed files with 25 additions and 0 deletions

12
log.cpp
View File

@ -133,3 +133,15 @@ util::detail::log (level_t level, boost::format &&format) {
<< format
<< std::endl;
}
scoped_logger::scoped_logger (const level_t _level,
const std::string &_message):
m_level (_level),
m_message (_message)
{ ; }
scoped_logger::~scoped_logger () {
log (m_level, m_message);
}

13
log.hpp
View File

@ -20,6 +20,8 @@
#ifndef __UTIL_LOG_HPP
#define __UTIL_LOG_HPP
#include "nocopy.hpp"
#include <iostream>
#include <string>
@ -69,6 +71,17 @@ namespace util {
#else
#define LOG_DEBUG(...) do { ; } while (0)
#endif
class scoped_logger : public nocopy {
public:
scoped_logger (const level_t, const std::string&);
~scoped_logger ();
protected:
const level_t m_level;
const std::string &m_message;
};
}
#include "log.ipp"