123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #ifndef LOGGER_H
- #define LOGGER_H
- #include "core/os/file_access.h"
- #include "core/ustring.h"
- #include "core/vector.h"
- #include <stdarg.h>
- class Logger {
- protected:
- bool should_log(bool p_err);
- public:
- enum ErrorType {
- ERR_ERROR,
- ERR_WARNING,
- ERR_SCRIPT,
- ERR_SHADER
- };
- virtual void logv(const char *p_format, va_list p_list, bool p_err) = 0;
- virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
- void logf(const char *p_format, ...);
- void logf_error(const char *p_format, ...);
- virtual ~Logger();
- };
- class StdLogger : public Logger {
- public:
- virtual void logv(const char *p_format, va_list p_list, bool p_err);
- virtual ~StdLogger();
- };
- class RotatedFileLogger : public Logger {
- String base_path;
- int max_files;
- FileAccess *file;
- void rotate_file_without_closing();
- void close_file();
- void clear_old_backups();
- void rotate_file();
- public:
- RotatedFileLogger(const String &p_base_path, int p_max_files = 10);
- virtual void logv(const char *p_format, va_list p_list, bool p_err);
- virtual ~RotatedFileLogger();
- };
- class CompositeLogger : public Logger {
- Vector<Logger *> loggers;
- public:
- CompositeLogger(Vector<Logger *> p_loggers);
- virtual void logv(const char *p_format, va_list p_list, bool p_err);
- virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
- void add_logger(Logger *p_logger);
- virtual ~CompositeLogger();
- };
- #endif
|