42 lines
1.6 KiB
C++
42 lines
1.6 KiB
C++
|
#pragma once
|
||
|
#include <stdio.h>
|
||
|
#include <streambuf>
|
||
|
#include <ostream>
|
||
|
#include <set>
|
||
|
#include <vector>
|
||
|
namespace Looper::Log {
|
||
|
struct LogStream {
|
||
|
std::set<FILE *> outputs;
|
||
|
static std::set<FILE *> global_outputs;
|
||
|
int my_log_level;
|
||
|
std::set<LogStream*> streams;
|
||
|
bool nested;
|
||
|
bool need_prefix;
|
||
|
std::vector<std::string> names;
|
||
|
std::set<FILE*> get_used_outputs();
|
||
|
LogStream(std::initializer_list<std::string> names, int log_level, bool nested);
|
||
|
public:
|
||
|
static int log_level;
|
||
|
void writeprefix();
|
||
|
void writeln(const char *msg);
|
||
|
void writeln_n(const char *msg, size_t n);
|
||
|
void writeln(std::string msg);
|
||
|
void writes(const char *msg);
|
||
|
void writesn(const char *msg, size_t n);
|
||
|
void writes(std::string msg);
|
||
|
void writec(const char chr);
|
||
|
void vwritef(const char *fmt, va_list args);
|
||
|
void writef(const char *fmt, ...);
|
||
|
void vwritefln(const char *fmt, va_list args);
|
||
|
void writefln(const char *fmt, ...);
|
||
|
LogStream(std::initializer_list<std::string> names, std::initializer_list<LogStream*> streams, int log_level = 0);
|
||
|
LogStream(std::initializer_list<std::string> names, std::initializer_list<FILE*> outputs, int log_level = 0);
|
||
|
};
|
||
|
void init_logging();
|
||
|
LogStream &get_log_stream_by_level(int level);
|
||
|
#define DEBUG (Looper::Log::get_log_stream_by_level(-1))
|
||
|
#define INFO (Looper::Log::get_log_stream_by_level(0))
|
||
|
#define WARNING (Looper::Log::get_log_stream_by_level(1))
|
||
|
#define ERROR (Looper::Log::get_log_stream_by_level(2))
|
||
|
|
||
|
}
|