forked from mia/Aegisub
Remove the usage of __FILE__
Prepare for reproducible build
This commit is contained in:
parent
2929b9db37
commit
309996aeb2
|
@ -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<nanoseconds>(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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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; }
|
||||
};
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
#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 @@ public:
|
|||
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 @@ public:
|
|||
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())
|
||||
|
|
Loading…
Reference in New Issue