diff --git a/libaegisub/common/log.cpp b/libaegisub/common/log.cpp index 575033021..1fbd87f8e 100644 --- a/libaegisub/common/log.cpp +++ b/libaegisub/common/log.cpp @@ -81,13 +81,19 @@ decltype(LogSink::messages) LogSink::GetMessages() const { return ret; } +#ifdef LOG_WITH_FILE Message::Message(const char *section, Severity severity, const char *file, const char *func, int line) +#else +Message::Message(const char* section, Severity severity, const char* func, int line) +#endif : msg(buffer, sizeof buffer) { using namespace std::chrono; sm.section = section; sm.severity = severity; +#ifdef LOG_WITH_FILE sm.file = file; +#endif sm.func = func; sm.line = line; sm.time = duration_cast(steady_clock::now().time_since_epoch()).count(); @@ -109,7 +115,9 @@ void JsonEmitter::log(SinkMessage const& sm) { entry["usec"] = sm.time % 1000000000; entry["severity"] = sm.severity; entry["section"] = sm.section; +#ifdef LOG_WITH_FILE entry["file"] = sm.file; +#endif entry["func"] = sm.func; entry["line"] = sm.line; entry["message"] = sm.message; diff --git a/libaegisub/include/libaegisub/exception.h b/libaegisub/include/libaegisub/exception.h index 831e4a371..a38e1520e 100644 --- a/libaegisub/include/libaegisub/exception.h +++ b/libaegisub/include/libaegisub/exception.h @@ -98,12 +98,6 @@ namespace agi { std::string const& GetMessage() const { return message; } }; -/// @brief Convenience macro to include the current location in code -/// -/// Intended for use in error messages where it can sometimes be convenient to -/// indicate the exact position the error occurred at. -#define AG_WHERE " (at " __FILE__ ":" #__LINE__ ")" - /// @brief Convenience macro for declaring exceptions /// @param classname Name of the exception class to declare /// @param baseclass Class to derive from diff --git a/libaegisub/include/libaegisub/log.h b/libaegisub/include/libaegisub/log.h index d980b3b80..c9c812f8b 100644 --- a/libaegisub/include/libaegisub/log.h +++ b/libaegisub/include/libaegisub/log.h @@ -21,7 +21,11 @@ // These macros below aren't a perm solution, it will depend on how annoying they are through // actual usage, and also depends on msvc support. +#ifdef LOG_WITH_FILE #define LOG_SINK(section, severity) agi::log::Message(section, severity, __FILE__, __FUNCTION__, __LINE__).stream() +#else +#define LOG_SINK(section, severity) agi::log::Message(section, severity, __FUNCTION__, __LINE__).stream() +#endif #define LOG_E(section) LOG_SINK(section, agi::log::Exception) #define LOG_A(section) LOG_SINK(section, agi::log::Assert) #define LOG_W(section) LOG_SINK(section, agi::log::Warning) @@ -59,7 +63,9 @@ struct SinkMessage { std::string message; ///< Formatted message int64_t time; ///< Time at execution in nanoseconds since epoch const char *section; ///< Section info eg "video/open" "video/seek" etc +#ifdef LOG_WITH_FILE const char *file; ///< Source file +#endif const char *func; ///< Function name Severity severity; ///< Severity int line; ///< Source line @@ -125,7 +131,11 @@ class Message { char buffer[2048]; public: - Message(const char *section, Severity severity, const char *file, const char *func, int line); +#ifdef LOG_WITH_FILE + Message(const char* section, Severity severity, const char* file, const char* func, int line); +#else + Message(const char* section, Severity severity, const char* func, int line); +#endif ~Message(); std::ostream& stream() { return msg; } }; diff --git a/libaegisub/unix/log.cpp b/libaegisub/unix/log.cpp index 82109dd2b..beb5d8470 100644 --- a/libaegisub/unix/log.cpp +++ b/libaegisub/unix/log.cpp @@ -24,14 +24,20 @@ void EmitSTDOUT::log(SinkMessage const& sm) { tm tmtime; localtime_r(&time, &tmtime); +#ifdef LOG_WITH_FILE printf("%c %02d:%02d:%02d %-9ld <%-25s> [%s:%s:%d] %.*s\n", +#else + printf("%c %02d:%02d:%02d %-9ld <%-25s> [%s:%d] %.*s\n", +#endif Severity_ID[sm.severity], tmtime.tm_hour, tmtime.tm_min, tmtime.tm_sec, (long)(sm.time % 1000000000), sm.section, +#ifdef LOG_WITH_FILE sm.file, +#endif sm.func, sm.line, (int)sm.message.size(), diff --git a/libaegisub/windows/log_win.cpp b/libaegisub/windows/log_win.cpp index 91017a8f5..ae572a7fa 100644 --- a/libaegisub/windows/log_win.cpp +++ b/libaegisub/windows/log_win.cpp @@ -27,8 +27,12 @@ void EmitSTDOUT::log(SinkMessage const& sm) { localtime_s(&tmtime, &time); char buff[65536]; +#ifdef LOG_WITH_FILE _snprintf_s(buff, _TRUNCATE, "%s (%d): %c %02d:%02d:%02d.%-3ld <%-25s> [%s] %.*s\n", sm.file, +#else + _snprintf_s(buff, _TRUNCATE, "Line %d: %c %02d:%02d:%02d.%-3ld <%-25s> [%s] %.*s\n", +#endif sm.line, Severity_ID[sm.severity], tmtime.tm_hour, diff --git a/src/dialog_log.cpp b/src/dialog_log.cpp index 96fad3fbd..48fe250b1 100644 --- a/src/dialog_log.cpp +++ b/src/dialog_log.cpp @@ -58,6 +58,7 @@ class EmitLog final : public agi::log::Emitter { #ifndef _WIN32 tm tmtime; localtime_r(&time, &tmtime); +#ifdef LOG_WITH_FILE auto log = fmt_wx("%c %02d:%02d:%02d %-6d <%-25s> [%s:%s:%d] %s\n", agi::log::Severity_ID[sm.severity], tmtime.tm_hour, @@ -70,6 +71,19 @@ class EmitLog final : public agi::log::Emitter { sm.line, sm.message); #else + auto log = fmt_wx("%c %02d:%02d:%02d %-6d <%-25s> [%s:%d] %s\n", + agi::log::Severity_ID[sm.severity], + tmtime.tm_hour, + tmtime.tm_min, + tmtime.tm_sec, + (sm.time % 1000000000), + sm.section, + sm.func, + sm.line, + sm.message); +#endif +#else +#ifdef LOG_WITH_FILE auto log = fmt_wx("%c %-6ld.%09ld <%-25s> [%s:%s:%d] %s\n", agi::log::Severity_ID[sm.severity], (sm.time / 1000000000), @@ -79,6 +93,16 @@ class EmitLog final : public agi::log::Emitter { sm.func, sm.line, sm.message); +#else + auto log = fmt_wx("%c %-6ld.%09ld <%-25s> [%s:%d] %s\n", + agi::log::Severity_ID[sm.severity], + (sm.time / 1000000000), + (sm.time % 1000000000), + sm.section, + sm.func, + sm.line, + sm.message); +#endif #endif if (wxIsMainThread())