47 lines
868 B
C++
47 lines
868 B
C++
#pragma once
|
|
|
|
#include <psemek/log/level.hpp>
|
|
|
|
#include <string>
|
|
#include <thread>
|
|
#include <sstream>
|
|
|
|
namespace psemek::log
|
|
{
|
|
|
|
void set_max_thread_name_length(std::size_t length);
|
|
|
|
void register_thread(std::string name);
|
|
void register_thread(std::thread::id id, std::string name);
|
|
|
|
void put_message(level l, std::string const & message);
|
|
|
|
struct log_stream
|
|
{
|
|
log_stream(level l)
|
|
: l_(l)
|
|
{}
|
|
|
|
~log_stream()
|
|
{
|
|
put_message(l_, os_.str());
|
|
}
|
|
|
|
template <typename T>
|
|
log_stream & operator << (T const & x)
|
|
{
|
|
static_cast<std::ostream &>(os_) << x;
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
level l_;
|
|
std::ostringstream os_;
|
|
};
|
|
|
|
inline log_stream debug() { return {level::debug}; }
|
|
inline log_stream info() { return {level::info}; }
|
|
inline log_stream warning() { return {level::warning}; }
|
|
inline log_stream error() { return {level::error}; }
|
|
|
|
}
|