summaryrefslogtreecommitdiff
path: root/core/io/logger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/logger.cpp')
-rw-r--r--core/io/logger.cpp60
1 files changed, 34 insertions, 26 deletions
diff --git a/core/io/logger.cpp b/core/io/logger.cpp
index ad0cc81023..da200f5717 100644
--- a/core/io/logger.cpp
+++ b/core/io/logger.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,9 +30,10 @@
#include "logger.h"
+#include "core/config/project_settings.h"
#include "core/os/dir_access.h"
#include "core/os/os.h"
-#include "core/print_string.h"
+#include "core/string/print_string.h"
#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define sprintf sprintf_s
@@ -49,18 +50,29 @@ void Logger::log_error(const char *p_function, const char *p_file, int p_line, c
const char *err_type = "ERROR";
switch (p_type) {
- case ERR_ERROR: err_type = "ERROR"; break;
- case ERR_WARNING: err_type = "WARNING"; break;
- case ERR_SCRIPT: err_type = "SCRIPT ERROR"; break;
- case ERR_SHADER: err_type = "SHADER ERROR"; break;
- default: ERR_PRINT("Unknown error type"); break;
+ case ERR_ERROR:
+ err_type = "ERROR";
+ break;
+ case ERR_WARNING:
+ err_type = "WARNING";
+ break;
+ case ERR_SCRIPT:
+ err_type = "SCRIPT ERROR";
+ break;
+ case ERR_SHADER:
+ err_type = "SHADER ERROR";
+ break;
+ default:
+ ERR_PRINT("Unknown error type");
+ break;
}
const char *err_details;
- if (p_rationale && *p_rationale)
+ if (p_rationale && *p_rationale) {
err_details = p_rationale;
- else
+ } else {
err_details = p_code;
+ }
logf_error("%s: %s\n", err_type, err_details);
logf_error(" at: %s (%s:%i) - %s\n", p_function, p_file, p_line, p_code);
@@ -92,8 +104,6 @@ void Logger::logf_error(const char *p_format, ...) {
va_end(argp);
}
-Logger::~Logger() {}
-
void RotatedFileLogger::close_file() {
if (file) {
memdelete(file);
@@ -143,7 +153,7 @@ void RotatedFileLogger::rotate_file() {
char timestamp[21];
OS::Date date = OS::get_singleton()->get_date();
OS::Time time = OS::get_singleton()->get_time();
- sprintf(timestamp, "-%04d-%02d-%02d-%02d-%02d-%02d", date.year, date.month, date.day, time.hour, time.min, time.sec);
+ sprintf(timestamp, "_%04d-%02d-%02d_%02d.%02d.%02d", date.year, date.month, date.day, time.hour, time.min, time.sec);
String backup_name = base_path.get_basename() + timestamp;
if (base_path.get_extension() != String()) {
@@ -170,8 +180,7 @@ void RotatedFileLogger::rotate_file() {
RotatedFileLogger::RotatedFileLogger(const String &p_base_path, int p_max_files) :
base_path(p_base_path.simplify_path()),
- max_files(p_max_files > 0 ? p_max_files : 1),
- file(nullptr) {
+ max_files(p_max_files > 0 ? p_max_files : 1) {
rotate_file();
}
@@ -193,15 +202,14 @@ void RotatedFileLogger::logv(const char *p_format, va_list p_list, bool p_err) {
}
va_end(list_copy);
file->store_buffer((uint8_t *)buf, len);
+
if (len >= static_buf_size) {
Memory::free_static(buf);
}
-#ifdef DEBUG_ENABLED
- const bool need_flush = true;
-#else
- bool need_flush = p_err;
-#endif
- if (need_flush) {
+
+ if (p_err || GLOBAL_GET("application/run/flush_stdout_on_print")) {
+ // Don't always flush when printing stdout to avoid performance
+ // issues when `print()` is spammed in release builds.
file->flush();
}
}
@@ -220,14 +228,14 @@ void StdLogger::logv(const char *p_format, va_list p_list, bool p_err) {
vfprintf(stderr, p_format, p_list);
} else {
vprintf(p_format, p_list);
-#ifdef DEBUG_ENABLED
- fflush(stdout);
-#endif
+ if (GLOBAL_GET("application/run/flush_stdout_on_print")) {
+ // Don't always flush when printing stdout to avoid performance
+ // issues when `print()` is spammed in release builds.
+ fflush(stdout);
+ }
}
}
-StdLogger::~StdLogger() {}
-
CompositeLogger::CompositeLogger(Vector<Logger *> p_loggers) :
loggers(p_loggers) {
}