looper/log.hpp

62 lines
2 KiB
C++
Raw Normal View History

#pragma once
#include <stdio.h>
#include <streambuf>
#include <ostream>
#include <set>
2024-05-01 09:07:08 -07:00
#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);
2024-05-02 14:52:11 -07:00
#define LOG(level) (Looper::Log::get_log_stream_by_level(level))
#define DEBUG LOG(-1)
#define INFO LOG(0)
#define WARNING LOG(1)
#define ERROR LOG(2)
}
extern "C" {
void write_log(int level, const char *log);
void write_logln(int level, const char *log);
}