Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
Remove the usage of __FILE__
Browse files Browse the repository at this point in the history
Prepare for reproducible build
  • Loading branch information
wangqr committed Nov 2, 2019
1 parent 6865df1 commit f373fec
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
8 changes: 8 additions & 0 deletions libaegisub/common/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions libaegisub/include/libaegisub/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion libaegisub/include/libaegisub/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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; }
};
Expand Down
6 changes: 6 additions & 0 deletions libaegisub/unix/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions libaegisub/windows/log_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/dialog_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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())
Expand Down

0 comments on commit f373fec

Please sign in to comment.