add boost index type in the logger

This commit is contained in:
chatlanin 2022-03-30 14:13:55 +03:00
parent 393aa844a4
commit dbd0a07f57
3 changed files with 35 additions and 14 deletions

View File

@ -33,6 +33,11 @@ int minus(int a)
return a--;
}
struct ForTypeTrace
{
int a;
};
int main(int argc, char *argv[])
{
{// ex: string::split_str
@ -48,16 +53,19 @@ int main(int argc, char *argv[])
{// ex: container::vector_multiset
std::vector<std::string> v;
hack::container::vector_multiset(v, "asdf", "qwer", "zcv");
for(const auto& c : v) std::cout << c << std::endl;
for(const auto& c : v) hack::log()(c);
}
{// ex: container::set_multiset
std::set<int> s;
hack::container::set_multiset(s, 1, 2, 3, 3, 2, 1);
for(const auto& c : s) std::cout << c << std::endl;
for(const auto& c : s) hack::log()(c);
}
{// ex: logger::log
int a = 10;
ForTypeTrace ftt { 1234 };
hack::log::type_trace(a, a, ftt);
hack::log()(1234, "run in main", 1234);
hack::warn(" # ")(1234, "run in main", 1234);
hack::error(" - ")(1234, "run in main", 1234);

View File

@ -22,8 +22,11 @@ elif compiler.get_id() == 'clang'
message('Compiler: LLVM/clang')
endif
boost_dep = dependency('boost')
args = []
deps = []
deps += boost_dep
inc = []
subdir('src')

View File

@ -2,6 +2,8 @@
#include <experimental/source_location>
#include "boost/type_index.hpp"
#include "view/color.hpp"
#include "concepts/concepts.hpp"
#include "iterators/sequence_ostream_iterator.hpp"
@ -10,6 +12,15 @@
namespace hack
{
template<typename T, typename U>
void prepare(T t, U u)
{
std::cout << t
<< u.file_name() << ":" << view::color::reset
<< view::color::italic << view::color::yellow << u.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << u.line() << "]" << view::color::reset << ": ";
}
class log
{
public:
@ -21,14 +32,19 @@ namespace hack
template<typename... Args>
void operator() (const Args&... args)
{
std::cout << make_type_view
<< location.file_name() << ":" << view::color::reset
<< view::color::italic << view::color::yellow << location.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << location.line() << "]" << view::color::reset << ": ";
count = sizeof...(Args);
prepare(make_type_view, location);
print(args...);
}
template<typename... Args>
static void type_trace(const Args&... args)
{
std::cout << make_type_view << ": " << view::color::reset;
count = sizeof...(Args);
print(boost::typeindex::type_id<Args>().pretty_name()...);
}
private:
std::experimental::source_location location;
static int count;
@ -127,10 +143,7 @@ namespace hack
template<typename... Args>
void operator() (const Args&... args)
{
std::cout << make_type_view
<< location.file_name() << ":" << view::color::reset
<< view::color::italic << view::color::yellow << location.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << location.line() << "]" << view::color::reset << ": ";
prepare(make_type_view, location);
count = sizeof...(Args);
print(args...);
}
@ -157,10 +170,7 @@ namespace hack
template<typename... Args>
void operator() (const Args&... args)
{
std::cout << make_type_view
<< location.file_name() << ":" << view::color::reset
<< view::color::italic << view::color::yellow << location.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << location.line() << "]" << view::color::reset << ": ";
prepare(make_type_view, location);
count = sizeof...(Args);
print(args...);
}