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

Add Command to Set Logging/Filter Rules at Runtime #4637

Merged
merged 10 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Bugfix: Fixed Ctrl+Backspace not working after Select All in chat search popup. (#4461)
- Bugfix: Fixed crash when scrolling up really fast. (#4621)
- Dev: Added the ability to control the `followRedirect` mode for requests. (#4594)
- Dev: Added command to set Qt's logging filter/rules at runtime (`/c2:loggingrules`). (#4637)
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved

## 2.4.3

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ set(SOURCE_FILES
controllers/accounts/AccountModel.cpp
controllers/accounts/AccountModel.hpp

controllers/commands/builtin/chatterino/Debugging.cpp
controllers/commands/builtin/chatterino/Debugging.hpp
controllers/commands/builtin/twitch/ChatSettings.cpp
controllers/commands/builtin/twitch/ChatSettings.hpp
controllers/commands/builtin/twitch/ShieldMode.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "common/QLogging.hpp"
#include "common/SignalVector.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/builtin/chatterino/Debugging.hpp"
#include "controllers/commands/builtin/twitch/ChatSettings.hpp"
#include "controllers/commands/builtin/twitch/ShieldMode.hpp"
#include "controllers/commands/Command.hpp"
Expand Down Expand Up @@ -3211,6 +3212,8 @@ void CommandController::initialize(Settings &, Paths &paths)

this->registerCommand("/shield", &commands::shieldModeOn);
this->registerCommand("/shieldoff", &commands::shieldModeOff);

this->registerCommand("/c2:loggingrules", &commands::setLoggingRules);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is the hardest part - I think I would prefer /c2-set-logging-rules but happy to discuss it further before merging this in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good name to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love for us to come up with some convention for release-debug and debug-only commands. I typically use /debug- for release-debug.

}

void CommandController::save()
Expand Down
44 changes: 44 additions & 0 deletions src/controllers/commands/builtin/chatterino/Debugging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "controllers/commands/builtin/chatterino/Debugging.hpp"

#include "common/Channel.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "messages/MessageBuilder.hpp"

#include <QLoggingCategory>
#include <QString>

namespace chatterino::commands {
pajlada marked this conversation as resolved.
Show resolved Hide resolved

QString setLoggingRules(const CommandContext &ctx)
{
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
"Usage: /c2:loggingrules <rules...>. To enable debug logging for "
"all "
"categories from chatterino, use 'chatterino.*.debug=true'. For "
"the format on the rules, see "
"https://doc.qt.io/qt-6/"
"qloggingcategory.html#configuring-categories"));
return {};
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
}

QLoggingCategory::setFilterRules(
QList(ctx.words.begin() + 1, ctx.words.end()).join('\n'));

auto message = QStringLiteral("Updated filter rules.");
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved

if (!qgetenv("QT_LOGGING_RULES").isEmpty())
{
message += QStringLiteral(
" Warning: Logging rules were previously set by the "
"QT_LOGGING_RULES environment variable. This might cause "
"interference - see: "
"https://doc.qt.io/qt-6/qloggingcategory.html#setFilterRules");
}

ctx.channel->addMessage(makeSystemMessage(message));
return "";
}

} // namespace chatterino::commands
15 changes: 15 additions & 0 deletions src/controllers/commands/builtin/chatterino/Debugging.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

class QString;

namespace chatterino {

struct CommandContext;

namespace commands {

QString setLoggingRules(const CommandContext &ctx);

} // namespace commands

} // namespace chatterino
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved