-
Notifications
You must be signed in to change notification settings - Fork 1
/
ygamelog.h
76 lines (54 loc) · 2.13 KB
/
ygamelog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Created by Daniel on 2024-03-19.
//
#ifndef YGAMELOG_H
#define YGAMELOG_H
#include "core/config/project_settings.h"
#include "core/io/logger.h"
#include "core/object/ref_counted.h"
#include "core/os/os.h"
#include "core/string/ustring.h"
#include <stdarg.h>
class YGameLog : public RefCounted {
GDCLASS(YGameLog, RefCounted);
protected:
static Ref<YGameLog> singleton;
static void _bind_methods();
public:
static YGameLog *get_singleton();
static void set_singleton(const Ref<YGameLog> &ref) {
singleton = ref;
}
bool output_logging_on = false;
void SetupOutputLogging();
Vector<String> logged;
Vector<Variant> loggedVariants;
int get_log_count() const {return static_cast<int>(logged.size());}
Vector<String> get_logged() const {return logged;}
void set_logged(const Vector<String> &p_logged) {logged = p_logged;}
void log_message(const String &new_message) { logged.push_back(new_message); }
void clear_log() { logged.clear(); }
int get_variant_log_count() const {return static_cast<int>(loggedVariants.size());}
Vector<Variant> get_logged_variants() const {return loggedVariants;}
void set_logged_variants(const Vector<Variant> &p_logged) {loggedVariants = p_logged;}
void log_variant(const Variant &new_message) { loggedVariants.push_back(new_message); }
void clear_variant_log() { loggedVariants.clear(); }
YGameLog() { }
~YGameLog() {
logged.clear();
loggedVariants.clear();
if(singleton.is_valid() && singleton == this) {
singleton.unref();
}
}
};
class YLogger : public Logger {
public:
virtual void logv(const char *p_format, va_list p_list, bool p_err) override _PRINTF_FORMAT_ATTRIBUTE_2_0;
void logf_error_custom(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
bool last_pushed_was_warning=false;
bool last_pushed_was_error=false;
virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type = ERR_ERROR) override;
virtual ~YLogger() {}
};
#endif //YGAMELOG_H