Logging: Formatting
This commit is contained in:
parent
642a455a9c
commit
7697bbfa4e
@ -94,7 +94,7 @@ class DebugBase : public QDebug {
|
|||||||
DebugBase() : QDebug(sNullDevice) {}
|
DebugBase() : QDebug(sNullDevice) {}
|
||||||
explicit DebugBase(QtMsgType t) : QDebug(t) {}
|
explicit DebugBase(QtMsgType t) : QDebug(t) {}
|
||||||
T &space() { return static_cast<T&>(QDebug::space()); }
|
T &space() { return static_cast<T&>(QDebug::space()); }
|
||||||
T& noSpace() { return static_cast<T&>(QDebug::nospace()); }
|
T &nospace() { return static_cast<T&>(QDebug::nospace()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Debug message will be stored in a buffer.
|
// Debug message will be stored in a buffer.
|
||||||
@ -173,6 +173,7 @@ void Init() {
|
|||||||
if (!sOriginalMessageHandler) {
|
if (!sOriginalMessageHandler) {
|
||||||
sOriginalMessageHandler = qInstallMessageHandler(MessageHandler);
|
sOriginalMessageHandler = qInstallMessageHandler(MessageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetLevels(const QString &levels) {
|
void SetLevels(const QString &levels) {
|
||||||
@ -229,6 +230,7 @@ static QString ParsePrettyFunction(const char *pretty_function) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return class_name;
|
return class_name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -269,11 +271,10 @@ static T CreateLogger(Level level, const QString &class_name, int line, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
T ret(type);
|
T ret(type);
|
||||||
ret.nospace() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz").toLatin1().constData()
|
ret.nospace() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz").toLatin1().constData() << level_name << function_line.leftJustified(32).toLatin1().constData();
|
||||||
<< level_name
|
|
||||||
<< function_line.leftJustified(32).toLatin1().constData();
|
|
||||||
|
|
||||||
return ret.space();
|
return ret.space();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
@ -303,6 +304,7 @@ QString LinuxDemangle(const QString &symbol) {
|
|||||||
}
|
}
|
||||||
QString mangled_function = match.captured(1);
|
QString mangled_function = match.captured(1);
|
||||||
return CXXDemangle(mangled_function);
|
return CXXDemangle(mangled_function);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // Q_OS_LINUX
|
#endif // Q_OS_LINUX
|
||||||
|
|
||||||
@ -323,6 +325,7 @@ QString DarwinDemangle(const QString &symbol) {
|
|||||||
|
|
||||||
QString DemangleSymbol(const QString &symbol);
|
QString DemangleSymbol(const QString &symbol);
|
||||||
QString DemangleSymbol(const QString &symbol) {
|
QString DemangleSymbol(const QString &symbol) {
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
return DarwinDemangle(symbol);
|
return DarwinDemangle(symbol);
|
||||||
#elif defined(Q_OS_LINUX)
|
#elif defined(Q_OS_LINUX)
|
||||||
@ -330,9 +333,11 @@ QString DemangleSymbol(const QString &symbol) {
|
|||||||
#else
|
#else
|
||||||
return symbol;
|
return symbol;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DumpStackTrace() {
|
void DumpStackTrace() {
|
||||||
|
|
||||||
#ifdef HAVE_BACKTRACE
|
#ifdef HAVE_BACKTRACE
|
||||||
void *callstack[128];
|
void *callstack[128];
|
||||||
int callstack_size = backtrace(reinterpret_cast<void**>(&callstack), sizeof(callstack));
|
int callstack_size = backtrace(reinterpret_cast<void**>(&callstack), sizeof(callstack));
|
||||||
@ -345,11 +350,11 @@ void DumpStackTrace() {
|
|||||||
#else
|
#else
|
||||||
qLog(Debug) << "FIXME: Implement printing stack traces on this platform";
|
qLog(Debug) << "FIXME: Implement printing stack traces on this platform";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are the functions that create loggers for the rest of Clementine.
|
// These are the functions that create loggers for the rest of Strawberry.
|
||||||
// It's okay that the LoggedDebug instance is copied to a QDebug in these. It
|
// It's okay that the LoggedDebug instance is copied to a QDebug in these. It doesn't override any behavior that should be needed after return.
|
||||||
// doesn't override any behavior that should be needed after return.
|
|
||||||
#define qCreateLogger(line, pretty_function, category, level) logging::CreateLogger<LoggedDebug>(logging::Level_##level, logging::ParsePrettyFunction(pretty_function), line, category)
|
#define qCreateLogger(line, pretty_function, category, level) logging::CreateLogger<LoggedDebug>(logging::Level_##level, logging::ParsePrettyFunction(pretty_function), line, category)
|
||||||
|
|
||||||
QDebug CreateLoggerInfo(int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Info); }
|
QDebug CreateLoggerInfo(int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Info); }
|
||||||
@ -383,4 +388,3 @@ QDebug operator<<(QDebug dbg, std::chrono::seconds secs) {
|
|||||||
dbg.nospace() << print_duration(secs, "s");
|
dbg.nospace() << print_duration(secs, "s");
|
||||||
return dbg.space();
|
return dbg.space();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,6 @@ QDebug CreateLoggerError(int line, const char *pretty_function, const char* cate
|
|||||||
QDebug CreateLoggerDebug(int line, const char *pretty_function, const char *category);
|
QDebug CreateLoggerDebug(int line, const char *pretty_function, const char *category);
|
||||||
#endif // QT_NO_DEBUG_OUTPUT
|
#endif // QT_NO_DEBUG_OUTPUT
|
||||||
|
|
||||||
|
|
||||||
void GLog(const char *domain, int level, const char *message, void *user_data);
|
void GLog(const char *domain, int level, const char *message, void *user_data);
|
||||||
|
|
||||||
extern const char *kDefaultLogLevels;
|
extern const char *kDefaultLogLevels;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user