forked from mia/Aegisub
Make log messages a little saner
This commit is contained in:
parent
69e1744fc7
commit
101721863a
4 changed files with 19 additions and 48 deletions
|
@ -30,7 +30,6 @@
|
|||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace agi {
|
||||
namespace log {
|
||||
|
@ -42,24 +41,16 @@ LogSink *log;
|
|||
/// Keep this ordered the same as Severity
|
||||
const char *Severity_ID = "EAWID";
|
||||
|
||||
SinkMessage::SinkMessage(const char *section, Severity severity,
|
||||
const char *file, const char *func, int line,
|
||||
timeval tv)
|
||||
SinkMessage::SinkMessage(const char *section, Severity severity, const char *file, const char *func, int line, timeval tv)
|
||||
: section(section)
|
||||
, severity(severity)
|
||||
, file(file)
|
||||
, func(func)
|
||||
, line(line)
|
||||
, tv(tv)
|
||||
, message(nullptr)
|
||||
, len(0)
|
||||
{
|
||||
}
|
||||
|
||||
SinkMessage::~SinkMessage() {
|
||||
delete [] message;
|
||||
}
|
||||
|
||||
/// @todo The log files need to be trimmed after N amount.
|
||||
LogSink::~LogSink() {
|
||||
// The destructor for emitters may try to log messages, so disable all the
|
||||
|
@ -87,22 +78,16 @@ void LogSink::Unsubscribe(Emitter *em) {
|
|||
LOG_D("agi/log/emitter/unsubscribe") << "Un-Subscribe: " << this;
|
||||
}
|
||||
|
||||
Message::Message(const char *section,
|
||||
Severity severity,
|
||||
const char *file,
|
||||
const char *func,
|
||||
int line)
|
||||
: len(1024)
|
||||
, buf(new char[len])
|
||||
, msg(buf, len)
|
||||
Message::Message(const char *section, Severity severity, const char *file, const char *func, int line)
|
||||
: msg(nullptr, 1024)
|
||||
{
|
||||
sm = new SinkMessage(section, severity, file, func, line, util::time_log());
|
||||
}
|
||||
|
||||
Message::~Message() {
|
||||
sm->message = msg.str();
|
||||
sm->len = (size_t)msg.pcount();
|
||||
sm->message = std::string(msg.str(), (std::string::size_type)msg.pcount());
|
||||
agi::log::log->log(sm);
|
||||
msg.freeze(false);
|
||||
}
|
||||
|
||||
JsonEmitter::JsonEmitter(agi::fs::path const& directory, const agi::log::LogSink *log_sink)
|
||||
|
@ -128,7 +113,7 @@ JsonEmitter::~JsonEmitter() {
|
|||
entry["file"] = sink[i]->file;
|
||||
entry["func"] = sink[i]->func;
|
||||
entry["line"] = sink[i]->line;
|
||||
entry["message"] = std::string(sink[i]->message, sink[i]->len);
|
||||
entry["message"] = sink[i]->message;
|
||||
|
||||
array.push_back(std::move(entry));
|
||||
}
|
||||
|
|
|
@ -69,10 +69,7 @@ extern const char *Severity_ID;
|
|||
extern LogSink *log;
|
||||
|
||||
/// Container to hold a single message
|
||||
class SinkMessage {
|
||||
SinkMessage(SinkMessage const&);
|
||||
SinkMessage& operator=(SinkMessage const&);
|
||||
public:
|
||||
struct SinkMessage {
|
||||
/// @brief Constructor
|
||||
/// @param section Section info
|
||||
/// @param severity Severity
|
||||
|
@ -82,17 +79,13 @@ public:
|
|||
/// @param tv Log time
|
||||
SinkMessage(const char *section, Severity severity, const char *file, const char *func, int line, timeval tv);
|
||||
|
||||
/// Destructor
|
||||
~SinkMessage();
|
||||
|
||||
const char *section; ///< Section info eg "video/open" "video/seek" etc
|
||||
Severity severity; ///< Severity
|
||||
const char *file; ///< Source file
|
||||
const char *func; ///< Function name
|
||||
int line; ///< Source line
|
||||
agi_timeval tv; ///< Time at execution
|
||||
char *message; ///< Formatted message
|
||||
size_t len; ///< Message length
|
||||
std::string message; ///< Formatted message
|
||||
};
|
||||
|
||||
class Emitter;
|
||||
|
@ -164,28 +157,20 @@ public:
|
|||
|
||||
/// Generates a message and submits it to the log sink.
|
||||
class Message {
|
||||
const int len;
|
||||
char *buf;
|
||||
std::ostrstream msg;
|
||||
SinkMessage *sm;
|
||||
|
||||
public:
|
||||
Message(const char *section,
|
||||
Severity severity,
|
||||
const char *file,
|
||||
const char *func,
|
||||
int line);
|
||||
Message(const char *section, Severity severity, const char *file, const char *func, int line);
|
||||
~Message();
|
||||
std::ostream& stream() { return msg; }
|
||||
};
|
||||
|
||||
|
||||
/// Emit log entries to stdout.
|
||||
class EmitSTDOUT: public Emitter {
|
||||
public:
|
||||
void log(SinkMessage *sm);
|
||||
};
|
||||
|
||||
|
||||
} // namespace log
|
||||
} // namespace agi
|
||||
|
|
|
@ -36,7 +36,7 @@ void EmitSTDOUT::log(SinkMessage *sm) {
|
|||
time_t time = sm->tv.tv_sec;
|
||||
localtime_s(&tmtime, &time);
|
||||
|
||||
char buff[1024];
|
||||
char buff[65536];
|
||||
_snprintf_s(buff, _TRUNCATE, "%s (%d): %c %02d:%02d:%02d %-6ld <%-25s> [%s] %.*s\n",
|
||||
sm->file,
|
||||
sm->line,
|
||||
|
@ -47,8 +47,8 @@ void EmitSTDOUT::log(SinkMessage *sm) {
|
|||
sm->tv.tv_usec,
|
||||
sm->section,
|
||||
sm->func,
|
||||
sm->len,
|
||||
sm->message);
|
||||
sm->message.size(),
|
||||
sm->message.c_str());
|
||||
OutputDebugStringW(charset::ConvertW(buff).c_str());
|
||||
}
|
||||
} // namespace log
|
||||
|
|
|
@ -36,6 +36,11 @@
|
|||
|
||||
#include "dialog_log.h"
|
||||
|
||||
#include "compat.h"
|
||||
#include "include/aegisub/context.h"
|
||||
|
||||
#include <libaegisub/log.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
|
@ -46,10 +51,6 @@
|
|||
#include <wx/stattext.h>
|
||||
#include <wx/textctrl.h>
|
||||
|
||||
#include <libaegisub/log.h>
|
||||
|
||||
#include "include/aegisub/context.h"
|
||||
|
||||
class EmitLog : public agi::log::Emitter {
|
||||
wxTextCtrl *text_ctrl;
|
||||
public:
|
||||
|
@ -74,7 +75,7 @@ public:
|
|||
sm->file,
|
||||
sm->func,
|
||||
sm->line,
|
||||
wxString::FromUTF8(sm->message, sm->len));
|
||||
to_wx(sm->message));
|
||||
#else
|
||||
wxString log = wxString::Format("%c %-6ld <%-25s> [%s:%s:%d] %s\n",
|
||||
agi::log::Severity_ID[sm->severity],
|
||||
|
@ -83,7 +84,7 @@ public:
|
|||
sm->file,
|
||||
sm->func,
|
||||
sm->line,
|
||||
wxString::FromUTF8(sm->message, sm->len));
|
||||
to_wx(sm->message));
|
||||
#endif
|
||||
text_ctrl->AppendText(log);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue