Skip to content

Commit

Permalink
Make debug output a cmdline option
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSchneid3r committed Nov 16, 2017
1 parent 15ed2f3 commit 61b2adb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# Set additional compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") #-Wconversion -Wunused
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DQT_NO_DEBUG_OUTPUT")

include(GNUInstallDirs)

Expand Down
27 changes: 11 additions & 16 deletions lib/albertcore/src/core/albert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static SettingsWidget *settingsWidget;
static TrayIcon *trayIcon;
static QMenu *trayIconMenu;
static QLocalServer *localServer;
static bool printDebugOutput;


int Core::AlbertApp::run(int argc, char **argv) {
Expand Down Expand Up @@ -90,9 +91,13 @@ int Core::AlbertApp::run(int argc, char **argv) {
parser.addVersionOption();
parser.addOption(QCommandLineOption({"k", "hotkey"}, "Overwrite the hotkey to use.", "hotkey"));
parser.addOption(QCommandLineOption({"p", "plugin-dirs"}, "Set the plugin dirs to use. Comma separated.", "directory"));
parser.addOption(QCommandLineOption({"d", "debug"}, "Print debug output."));
parser.addPositionalArgument("command", "Command to send to a running instance, if any. (show, hide, toggle)", "[command]");
parser.process(*app);

if (parser.isSet("debug"))
printDebugOutput = true;


/*
* IPC/SINGLETON MECHANISM
Expand Down Expand Up @@ -482,30 +487,20 @@ int Core::AlbertApp::run(int argc, char **argv) {
/** ***************************************************************************/
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &message) {
switch (type) {
#ifdef QT_NO_DEBUG
case QtDebugMsg:
break;
case QtInfoMsg:
fprintf(stdout, "%s \x1b[0m[INFO]\x1b[0m %s\n",
QTime::currentTime().toString().toLocal8Bit().constData(),
message.toLocal8Bit().constData());
fflush(stdout);
break;
#else
case QtDebugMsg:
fprintf(stdout, "%s [DEBG] \x1b[3m%s -- [%s]\x1b[0m\n",
QTime::currentTime().toString().toLocal8Bit().constData(),
message.toLocal8Bit().constData(),
context.function);
fflush(stdout);
if (printDebugOutput) {
fprintf(stdout, "%s [DEBG] \x1b[3m%s\x1b[0m\n",
QTime::currentTime().toString().toLocal8Bit().constData(),
message.toLocal8Bit().constData());
fflush(stdout);
}
break;
case QtInfoMsg:
fprintf(stdout, "%s \x1b[32m[INFO]\x1b[0;1m %s\x1b[0m\n",
QTime::currentTime().toString().toLocal8Bit().constData(),
message.toLocal8Bit().constData());
fflush(stdout);
break;
#endif
case QtWarningMsg:
fprintf(stderr, "%s \x1b[33m[WARN]\x1b[0;1m %s\x1b[0m\n",
QTime::currentTime().toString().toLocal8Bit().constData(),
Expand Down

0 comments on commit 61b2adb

Please sign in to comment.