looper/log.hpp

58 lines
No EOL
2 KiB
C++

#pragma once
#include <stdio.h>
#include <streambuf>
#include <ostream>
#include <set>
#include <config.h>
#include <vector>
#include <variant>
#ifdef __ANDROID__
#include <android/log.h>
#endif
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();
#ifdef __ANDROID__
std::string line;
std::set<android_LogPriority> android_outputs;
#endif
LogStream(std::initializer_list<std::string> names, int log_level, bool nested, void* discriminator);
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);
#ifdef __ANDROID__
LogStream(std::initializer_list<std::string> names, std::initializer_list<std::variant<FILE*, android_LogPriority>> outputs, int log_level = 0);
#else
LogStream(std::initializer_list<std::string> names, std::initializer_list<FILE*> outputs, int log_level = 0);
#endif
};
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))
}