2024-03-23 18:41:26 -07:00
|
|
|
#pragma once
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <streambuf>
|
|
|
|
#include <ostream>
|
|
|
|
#include <set>
|
2024-05-01 09:07:08 -07:00
|
|
|
#include <config.h>
|
2024-03-23 18:41:26 -07:00
|
|
|
#include <vector>
|
2024-04-28 12:31:40 -07:00
|
|
|
#include <variant>
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
2024-03-23 18:41:26 -07:00
|
|
|
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();
|
2024-04-28 12:31:40 -07:00
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2024-03-23 18:41:26 -07:00
|
|
|
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);
|
2024-04-28 12:31:40 -07:00
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
LogStream(std::initializer_list<std::string> names, std::initializer_list<std::variant<FILE*, android_LogPriority>> outputs, int log_level = 0);
|
|
|
|
#else
|
2024-03-23 18:41:26 -07:00
|
|
|
LogStream(std::initializer_list<std::string> names, std::initializer_list<FILE*> outputs, int log_level = 0);
|
2024-04-28 12:31:40 -07:00
|
|
|
#endif
|
2024-03-23 18:41:26 -07:00
|
|
|
};
|
|
|
|
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))
|
|
|
|
|
|
|
|
}
|