mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:43:21 +02:00
Enable color by default on Unix, change to comma separators.
Also emit a message if an unrecognized log option is used.
This commit is contained in:
parent
895d4d4172
commit
1124590422
1 changed files with 29 additions and 11 deletions
|
@ -17,6 +17,10 @@
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
|
@ -33,22 +37,36 @@ LogHandler& LogHandler::getInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
LogHandler::LogHandler() {
|
LogHandler::LogHandler() {
|
||||||
QString log_options = qgetenv("VIRCADIA_LOG_OPTIONS").toLower();
|
QString logOptions = qgetenv("VIRCADIA_LOG_OPTIONS").toLower();
|
||||||
|
|
||||||
if (log_options.contains("color")) {
|
#ifdef Q_OS_UNIX
|
||||||
_useColor = 1;
|
// Enable color by default if we're on Unix, and output is a tty (so we're not being piped into something)
|
||||||
|
//
|
||||||
|
// On Windows the situation is more complex, and color is supported or not depending on version and
|
||||||
|
// registry settings, so for now it's off by default and it's up to the user to do what's required.
|
||||||
|
if (isatty(fileno(stdout))) {
|
||||||
|
_useColor = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (log_options.contains("process_id")) {
|
auto optionList = logOptions.split(",");
|
||||||
_shouldOutputProcessID = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (log_options.contains("thread_id")) {
|
for(auto option : optionList) {
|
||||||
_shouldOutputThreadID = true;
|
option = option.trimmed();
|
||||||
}
|
|
||||||
|
|
||||||
if (log_options.contains("milliseconds")) {
|
if (option == "color") {
|
||||||
_shouldDisplayMilliseconds = true;
|
_useColor = true;
|
||||||
|
} else if (option == "nocolor") {
|
||||||
|
_useColor = false;
|
||||||
|
} else if (option == "process_id") {
|
||||||
|
_shouldOutputProcessID = true;
|
||||||
|
} else if (option == "thread_id") {
|
||||||
|
_shouldOutputThreadID = true;
|
||||||
|
} else if (option == "milliseconds") {
|
||||||
|
_shouldDisplayMilliseconds = true;
|
||||||
|
} else if (option != "") {
|
||||||
|
fprintf(stdout, "Unrecognized option in VIRCADIA_LOG_OPTIONS: '%s'\n", option.toUtf8().constData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue