Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite logging system #180

Merged
merged 17 commits into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/advancebuttondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void AdvanceButtonDialog::joinSlot()
tr("It's only possible to join simple and mix keyboard slots"));
} else
{
qDebug() << "Chosen " << ui->slotListWidget->selectedItems().count() << " slots" << endl;
qDebug() << "Chosen " << ui->slotListWidget->selectedItems().count() << " slots";

QListWidgetItem *firstSelected = ui->slotListWidget->selectedItems().at(0);
QString text = "";
Expand Down Expand Up @@ -908,7 +908,7 @@ void AdvanceButtonDialog::updateSetSelection()
chosen_set = (ui->setSelectionComboBox->currentIndex() + 2) / 3;
}

qDebug() << "CONDITION: " << QString::number(condition_choice) << endl;
qDebug() << "CONDITION: " << QString::number(condition_choice);

switch (condition_choice)
{
Expand All @@ -925,7 +925,7 @@ void AdvanceButtonDialog::updateSetSelection()
break;
}

qDebug() << "CHOSEN SET: " << chosen_set << endl;
qDebug() << "CHOSEN SET: " << chosen_set;

} else
{
Expand Down
27 changes: 27 additions & 0 deletions src/antimicrosettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ void AntiMicroSettings::importFromCommandLine(CommandLineUtility &cmdutility)
getCmdSettings().setValue("DisplaySDLMapping", 1);
}
}
/**
* @brief applies settings from command line to logger
*
* @param cmdutility
* @param logger pointer to logger, if nullptr then getInstance() is used
*/
void AntiMicroSettings::applySettingsToLogger(CommandLineUtility &cmdutility, Logger *logger_ptr)
{
if (logger_ptr == nullptr)
logger_ptr = Logger::getInstance();

if (cmdutility.getCurrentLogLevel() != Logger::LOG_NONE)
{
logger_ptr->setLogLevel(cmdutility.getCurrentLogLevel());
} else if (contains("LogLevel"))
{
logger_ptr->setLogLevel(static_cast<Logger::LogLevel>(value("LogLevel").toInt()));
}

if (!cmdutility.getCurrentLogFile().isEmpty())
{
logger_ptr->setCurrentLogFile(cmdutility.getCurrentLogFile());
} else if (contains("LogFile"))
{
logger_ptr->setCurrentLogFile(value("LogFile").toString());
}
}

QMutex *AntiMicroSettings::getLock() { return &lock; }

Expand Down
2 changes: 2 additions & 0 deletions src/antimicrosettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class AntiMicroSettings : public QSettings
QMutex *getLock();
QSettings &getCmdSettings();

void applySettingsToLogger(CommandLineUtility &cmdutility, Logger *logger = nullptr);

protected:
QSettings cmdSettings;
QMutex lock;
Expand Down
40 changes: 19 additions & 21 deletions src/applaunchhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QDebug>
#include <QDesktopWidget>
#include <QMapIterator>
#include <QTextStream>
#include <QThread>

AppLaunchHelper::AppLaunchHelper(AntiMicroSettings *settings, bool graphical, QObject *parent)
Expand Down Expand Up @@ -100,37 +99,36 @@ void AppLaunchHelper::changeGamepadPollRate()

void AppLaunchHelper::printControllerList(QMap<SDL_JoystickID, InputDevice *> *joysticks)
{
QTextStream outstream(stdout);

outstream << QObject::tr("# of joysticks found: %1").arg(joysticks->size()) << endl;
outstream << endl;
outstream << QObject::tr("List Joysticks:") << endl;
outstream << QObject::tr("---------------") << endl;
PRINT_STDOUT() << QObject::tr("# of joysticks found: %1").arg(joysticks->size()) << "\n"
<< "\n"
<< QObject::tr("List Joysticks:") << "\n"
<< QObject::tr("---------------") << "\n";
QMapIterator<SDL_JoystickID, InputDevice *> iter(*joysticks);
int indexNumber = 1;

while (iter.hasNext())
{
InputDevice *tempdevice = iter.next().value();
outstream << QObject::tr("Joystick %1:").arg(indexNumber) << endl;
outstream << " " << QObject::tr("Index: %1").arg(tempdevice->getRealJoyNumber()) << endl;
// outstream << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << endl;
outstream << " " << QObject::tr("UniqueID: %1").arg(tempdevice->getUniqueIDString()) << endl;
outstream << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << endl;
outstream << " " << QObject::tr("VendorID: %1").arg(tempdevice->getVendorString()) << endl;
outstream << " " << QObject::tr("ProductID: %1").arg(tempdevice->getProductIDString()) << endl;
outstream << " " << QObject::tr("Product Version: %1").arg(tempdevice->getProductVersion()) << endl;
outstream << " " << QObject::tr("Name: %1").arg(tempdevice->getSDLName()) << endl;
PRINT_STDOUT() << QObject::tr("Joystick %1:").arg(indexNumber) << "\n"
<< " " << QObject::tr("Index: %1").arg(tempdevice->getRealJoyNumber()) << "\n"
<< " " << QObject::tr("UniqueID: %1").arg(tempdevice->getUniqueIDString()) << "\n"
<< " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << "\n"
<< " " << QObject::tr("VendorID: %1").arg(tempdevice->getVendorString()) << "\n"
<< " " << QObject::tr("ProductID: %1").arg(tempdevice->getProductIDString()) << "\n"
<< " " << QObject::tr("Product Version: %1").arg(tempdevice->getProductVersion()) << "\n"
<< " " << QObject::tr("Name: %1").arg(tempdevice->getSDLName()) << "\n";

// PRINT_STDOUT() << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << "\n";
QString gameControllerStatus = tempdevice->isGameController() ? QObject::tr("Yes") : QObject::tr("No");
outstream << " " << QObject::tr("Game Controller: %1").arg(gameControllerStatus) << endl;

outstream << " " << QObject::tr("# of Axes: %1").arg(tempdevice->getNumberRawAxes()) << endl;
outstream << " " << QObject::tr("# of Buttons: %1").arg(tempdevice->getNumberRawButtons()) << endl;
outstream << " " << QObject::tr("# of Hats: %1").arg(tempdevice->getNumberHats()) << endl;
PRINT_STDOUT() << " " << QObject::tr("Game Controller: %1").arg(gameControllerStatus) << "\n"
<< " " << QObject::tr("# of Axes: %1").arg(tempdevice->getNumberRawAxes()) << "\n"
<< " " << QObject::tr("# of Buttons: %1").arg(tempdevice->getNumberRawButtons()) << "\n"
<< " " << QObject::tr("# of Hats: %1").arg(tempdevice->getNumberHats()) << "\n";

if (iter.hasNext())
{
outstream << endl;
PRINT_STDOUT() << "\n";
indexNumber++;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/autoprofilewatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,37 @@ void AutoProfileWatcher::runAppCheck()
if (!getAppProfileAssignments().isEmpty())
{
appLocation = findAppLocation();
qDebug() << "appLocation is " << appLocation << endl;
qDebug() << "appLocation is " << appLocation;
}

// More portable check for whether antimicrox is the current application
// with focus.
QWidget *focusedWidget = qApp->activeWindow();
if (focusedWidget != nullptr)
qDebug() << "get active window of app" << endl;
qDebug() << "get active window of app";
QString nowWindow = QString();
QString nowWindowClass = QString();
QString nowWindowName = QString();

long currentWindow = X11Extras::getInstance()->getWindowInFocus();
qDebug() << "getWindowInFocus: " << currentWindow << endl;
qDebug() << "getWindowInFocus: " << currentWindow;

if (currentWindow > 0)
{
long tempWindow = X11Extras::getInstance()->findParentClient(currentWindow);
qDebug() << "findParentClient: " << tempWindow << endl;
qDebug() << "findParentClient: " << tempWindow;

if (tempWindow > 0)
currentWindow = tempWindow;

nowWindow = QString::number(currentWindow);
qDebug() << "number of window now: " << nowWindow << endl;
qDebug() << "number of window now: " << nowWindow;

nowWindowClass = X11Extras::getInstance()->getWindowClass(static_cast<Window>(currentWindow));
qDebug() << "class of window now: " << nowWindowClass << endl;
qDebug() << "class of window now: " << nowWindowClass;

nowWindowName = X11Extras::getInstance()->getWindowTitle(static_cast<Window>(currentWindow));
qDebug() << "title of window now: " << nowWindowName << endl;
qDebug() << "title of window now: " << nowWindowName;
}

qDebug() << "WINDOW CLASS: " << nowWindowClass;
Expand All @@ -125,7 +125,7 @@ void AutoProfileWatcher::runAppCheck()

bool checkForTitleChange = getWindowNameProfileAssignments().size() > 0;

qDebug() << "window profile assignments size: " << getWindowNameProfileAssignments().size() << endl;
qDebug() << "window profile assignments size: " << getWindowNameProfileAssignments().size();

qDebug() << "checkForTitleChange: " << checkForTitleChange;

Expand Down
4 changes: 2 additions & 2 deletions src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ QString keycodeToKeyString(int keycode, int alias)
tempstring[numchars] = '\0';
newkey = QString::fromUtf8(tempstring);

qDebug() << "NEWKEY:" << newkey << endl;
qDebug() << "NEWKEY LEGNTH:" << numchars << endl;
qDebug() << "NEWKEY:" << newkey;
qDebug() << "NEWKEY LEGNTH:" << numchars;
} else
{
newkey = tempkey;
Expand Down
4 changes: 1 addition & 3 deletions src/gamecontrollermappingdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <QModelIndexList>
#include <QStringList>
#include <QTableWidgetItem>
#include <QTextStream>
#include <QVariant>
#include <QWidget>

Expand Down Expand Up @@ -338,8 +337,7 @@ void GameControllerMappingDialog::saveChanges()

if (displayMapping)
{
QTextStream out(stdout);
out << generateSDLMappingString();
PRINT_STDOUT() << generateSDLMappingString();
}

emit mappingUpdate(mappingString, device);
Expand Down
8 changes: 4 additions & 4 deletions src/inputdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,12 +1250,12 @@ void InputDaemon::convertMappingsToUnique(QSettings *sett, QString guidString, Q
if (sett->contains(guidString))
{
QStringList gg = sett->value(guidString).toString().split(",");
qDebug() << "Convert guidString to uniqueString 1): " << gg << endl;
qDebug() << "Convert guidString to uniqueString 1): " << gg;
gg.removeFirst();
qDebug() << "Convert guidString to uniqueString 2): " << gg << endl;
qDebug() << "Convert guidString to uniqueString 2): " << gg;
gg.prepend(uniqueIdString);
qDebug() << "Convert guidString to uniqueString 3): " << gg << endl;
qDebug() << "Joined uniqueMapping: " << gg.join(",") << endl;
qDebug() << "Convert guidString to uniqueString 3): " << gg;
qDebug() << "Joined uniqueMapping: " << gg.join(",");
sett->setValue(uniqueIdString, gg.join(","));
sett->remove(guidString);
}
Expand Down
13 changes: 4 additions & 9 deletions src/joytabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
#include <QSpacerItem>
#include <QStackedWidget>
#include <QStringListIterator>
#include <QTextStream>
#include <QVBoxLayout>
#include <QWidget>

Expand Down Expand Up @@ -654,8 +653,7 @@ void JoyTabWidget::saveConfigFile()
msg.exec();
} else if (writer->hasError() && !this->window()->isEnabled())
{
QTextStream error(stderr);
error << writer->getErrorString() << endl;
PRINT_STDERR() << writer->getErrorString() << "\n";
} else
{
int existingIndex = configBox->findData(fileinfo.absoluteFilePath());
Expand Down Expand Up @@ -753,8 +751,7 @@ void JoyTabWidget::resetJoystick()
msg.exec();
} else if (reader->hasError() && !this->window()->isEnabled())
{
QTextStream error(stderr);
error << reader->getErrorString() << endl;
PRINT_STDERR() << reader->getErrorString() << "\n";
}

displayProfileEditNotification();
Expand Down Expand Up @@ -831,8 +828,7 @@ void JoyTabWidget::saveAsConfig()
msg.exec();
} else if (writer->hasError() && !this->window()->isEnabled())
{
QTextStream error(stderr);
error << writer->getErrorString() << endl;
PRINT_STDERR() << writer->getErrorString() << "\n";
} else
{
int existingIndex = configBox->findData(fileinfo.absoluteFilePath());
Expand Down Expand Up @@ -933,8 +929,7 @@ void JoyTabWidget::changeJoyConfig(int index)
msg.exec();
} else if (reader->hasError() && !this->window()->isEnabled())
{
QTextStream error(stderr);
error << reader->getErrorString() << endl;
PRINT_STDERR() << reader->getErrorString() << "\n";
}
} else if (index == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions src/keyboard/virtualkeypushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ VirtualKeyPushButton::VirtualKeyPushButton(QString xcodestring, QWidget *parent)
{
populateKnownAliases();

// qDebug() << "Question: " << X11KeySymToKeycode("KP_7") << endl;
// qDebug() << "Question: " << X11KeySymToKeycode(79) << endl;
// qDebug() << "Question: " << X11KeySymToKeycode("KP_7");
// qDebug() << "Question: " << X11KeySymToKeycode(79);
this->keycode = 0;
this->qkeyalias = 0;
this->xcodestring = "";
Expand Down
16 changes: 7 additions & 9 deletions src/localantimicroserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QDebug>
#include <QLocalServer>
#include <QLocalSocket>
#include <QTextStream>

LocalAntiMicroServer::LocalAntiMicroServer(QObject *parent)
: QObject(parent)
Expand All @@ -38,7 +37,7 @@ void LocalAntiMicroServer::startLocalServer()
bool removedServer = QLocalServer::removeServer(PadderCommon::localSocketKey);

if (!removedServer)
qDebug() << "Couldn't remove local server named " << PadderCommon::localSocketKey << endl;
qDebug() << "Couldn't remove local server named " << PadderCommon::localSocketKey;

if (localServer->maxPendingConnections() != 1)
localServer->setMaxPendingConnections(1);
Expand All @@ -47,20 +46,19 @@ void LocalAntiMicroServer::startLocalServer()
{
if (!localServer->listen(PadderCommon::localSocketKey))
{
QTextStream errorstream(stderr);
QString message("Could not start signal server. Profiles cannot be reloaded\n");
message.append("from command-line");
errorstream << tr(message.toStdString().c_str()) << endl;
PRINT_STDERR() << tr(message.toStdString().c_str()) << "\n";
qDebug() << "Could not start signal server. Profiles cannot be reloaded\n"
<< " \nfrom command-line\n " << tr(message.toStdString().c_str()) << endl;
<< " \nfrom command-line\n " << tr(message.toStdString().c_str());
} else
{
connect(localServer, &QLocalServer::newConnection, this, &LocalAntiMicroServer::handleOutsideConnection);
}
}
} else
{
qDebug() << "LocalAntiMicroXServer::startLocalServer(): localServer is nullptr" << endl;
qDebug() << "LocalAntiMicroXServer::startLocalServer(): localServer is nullptr";
}
}

Expand All @@ -72,16 +70,16 @@ void LocalAntiMicroServer::handleOutsideConnection()

if (socket != nullptr)
{
qDebug() << "There is next pending connection: " << socket->socketDescriptor() << endl;
qDebug() << "There is next pending connection: " << socket->socketDescriptor();
connect(socket, &QLocalSocket::disconnected, this, &LocalAntiMicroServer::handleSocketDisconnect);
connect(socket, &QLocalSocket::disconnected, socket, &QLocalSocket::deleteLater);
} else
{
qDebug() << "There isn't next pending connection: " << endl;
qDebug() << "There isn't next pending connection: ";
}
} else
{
qDebug() << "LocalAntiMicroXServer::handleOutsideConnection(): localServer is nullptr" << endl;
qDebug() << "LocalAntiMicroXServer::handleOutsideConnection(): localServer is nullptr";
}
}

Expand Down
Loading