Skip to content

Commit

Permalink
Add log level which prints performed actions
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Mar 2, 2024
1 parent e9ea2e8 commit 5cb48cb
Show file tree
Hide file tree
Showing 56 changed files with 138 additions and 94 deletions.
4 changes: 4 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchToRandom="Switch to an
AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchTo="Switch to:"
AdvSceneSwitcher.generalTab.generalBehavior.cooldown="After performing actions skip performing actions for"
AdvSceneSwitcher.generalTab.generalBehavior.cooldownHint="During this time potential matches will be ignored!"
AdvSceneSwitcher.generalTab.generalBehavior.logLevel="Log level:"
AdvSceneSwitcher.generalTab.generalBehavior.logLevel.default="Default"
AdvSceneSwitcher.generalTab.generalBehavior.logLevel.printActions="Log performed actions"
AdvSceneSwitcher.generalTab.generalBehavior.logLevel.verbose="Verbose logging"
AdvSceneSwitcher.generalTab.generalBehavior.verboseLogging="Enable verbose logging"
AdvSceneSwitcher.generalTab.generalBehavior.saveWindowGeo="Save window position and size"
AdvSceneSwitcher.generalTab.generalBehavior.showTrayNotifications="Show system tray notifications"
Expand Down
25 changes: 22 additions & 3 deletions forms/advanced-scene-switcher.ui
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,31 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_52">
<item>
<widget class="QCheckBox" name="verboseLogging">
<widget class="QLabel" name="label_21">
<property name="text">
<string>AdvSceneSwitcher.generalTab.generalBehavior.verboseLogging</string>
<string>AdvSceneSwitcher.generalTab.generalBehavior.logLevel</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="logLevel">
<item>
<property name="text">
<string>AdvSceneSwitcher.generalTab.generalBehavior.logLevel.default</string>
</property>
</item>
<item>
<property name="text">
<string>AdvSceneSwitcher.generalTab.generalBehavior.logLevel.printActions</string>
</property>
</item>
<item>
<property name="text">
<string>AdvSceneSwitcher.generalTab.generalBehavior.logLevel.verbose</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_49">
<property name="orientation">
Expand Down Expand Up @@ -5078,7 +5097,7 @@
<tabstop>checkInterval</tabstop>
<tabstop>startupBehavior</tabstop>
<tabstop>autoStartEvent</tabstop>
<tabstop>verboseLogging</tabstop>
<tabstop>logLevel</tabstop>
<tabstop>saveWindowGeo</tabstop>
<tabstop>showTrayNotifications</tabstop>
<tabstop>uiHintsDisable</tabstop>
Expand Down
2 changes: 1 addition & 1 deletion lib/advanced-scene-switcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public slots:
void NoMatchDelayDurationChanged(const Duration &);
void CooldownDurationChanged(const Duration &);
void on_startupBehavior_currentIndexChanged(int index);
void on_logLevel_currentIndexChanged(int index);
void on_autoStartEvent_currentIndexChanged(int index);
void on_noMatchSwitchScene_currentTextChanged(const QString &text);
void on_checkInterval_valueChanged(int value);
void on_tabMoved(int from, int to);
void on_tabWidget_currentChanged(int index);
void on_exportSettings_clicked();
void on_importSettings_clicked();
void on_verboseLogging_stateChanged(int state);
void on_saveWindowGeo_stateChanged(int state);
void on_showTrayNotifications_stateChanged(int state);
void on_uiHintsDisable_stateChanged(int state);
Expand Down
24 changes: 12 additions & 12 deletions lib/general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ void AdvSceneSwitcher::on_startupBehavior_currentIndexChanged(int index)
static_cast<SwitcherData::StartupBehavior>(index);
}

void AdvSceneSwitcher::on_logLevel_currentIndexChanged(int value)
{
if (loading) {
return;
}
switcher->logLevel = static_cast<SwitcherData::LogLevel>(value);
}

void AdvSceneSwitcher::on_autoStartEvent_currentIndexChanged(int index)
{
if (loading) {
Expand Down Expand Up @@ -157,15 +165,6 @@ void AdvSceneSwitcher::closeEvent(QCloseEvent *)
obs_frontend_save();
}

void AdvSceneSwitcher::on_verboseLogging_stateChanged(int state)
{
if (loading) {
return;
}

switcher->verbose = state;
}

void AdvSceneSwitcher::on_saveWindowGeo_stateChanged(int state)
{
if (loading) {
Expand Down Expand Up @@ -598,7 +597,7 @@ void SwitcherData::SaveGeneralSettings(obs_data_t *obj)
obs_data_set_int(obj, "autoStartEvent",
static_cast<int>(autoStartEvent));

obs_data_set_bool(obj, "verbose", verbose);
obs_data_set_int(obj, "logLevel", static_cast<int>(logLevel));
obs_data_set_bool(obj, "showSystemTrayNotifications",
showSystemTrayNotifications);
obs_data_set_bool(obj, "disableHints", disableHints);
Expand Down Expand Up @@ -649,7 +648,7 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj)
autoStartEvent =
static_cast<AutoStart>(obs_data_get_int(obj, "autoStartEvent"));

verbose = obs_data_get_bool(obj, "verbose");
logLevel = static_cast<LogLevel>(obs_data_get_int(obj, "logLevel"));
showSystemTrayNotifications =
obs_data_get_bool(obj, "showSystemTrayNotifications");
disableHints = obs_data_get_bool(obj, "disableHints");
Expand Down Expand Up @@ -940,7 +939,8 @@ void AdvSceneSwitcher::SetupGeneralTab()
SIGNAL(DurationChanged(const Duration &)), this,
SLOT(CooldownDurationChanged(const Duration &)));

ui->verboseLogging->setChecked(switcher->verbose);
ui->logLevel->setCurrentIndex(static_cast<int>(switcher->logLevel));

ui->saveWindowGeo->setChecked(switcher->saveWindowGeo);
ui->showTrayNotifications->setChecked(
switcher->showSystemTrayNotifications);
Expand Down
4 changes: 2 additions & 2 deletions lib/legacy/switch-audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void SwitcherData::checkAudioSwitchFallback(OBSWeakSource &scene,
scene = audioFallback.getScene();
transition = audioFallback.transition;

if (verbose) {
if (VerboseLoggingEnabled()) {
audioFallback.logMatch();
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ bool SwitcherData::checkAudioSwitch(OBSWeakSource &scene,
transition = s.transition;
match = true;

if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool SwitcherData::checkExeSwitch(OBSWeakSource &scene,
scene = s.getScene();
transition = s.transition;

if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ bool SwitcherData::checkFileContent(OBSWeakSource &scene,
transition = s.transition;
match = true;

if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool SwitcherData::checkIdleSwitch(OBSWeakSource &scene,
match = true;
idleData.alreadySwitched = true;

if (verbose) {
if (VerboseLoggingEnabled()) {
idleData.logMatch();
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool SwitcherData::checkMediaSwitch(OBSWeakSource &scene,
scene = mediaSwitch.getScene();
transition = mediaSwitch.transition;

if (verbose) {
if (VerboseLoggingEnabled()) {
mediaSwitch.logMatch();
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/legacy/switch-network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void WSServer::sendMessage(SceneSwitchInfo sceneSwitch, bool preview)
}
}

if (switcher->verbose) {
if (VerboseLoggingEnabled()) {
blog(LOG_INFO, "server sent message:\n%s", message.c_str());
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ std::string processMessage(std::string payload)
std::string ret = "message ok";

auto transition = GetWeakTransitionByName(transitionName.c_str());
if (switcher->verbose && !transition) {
if (VerboseLoggingEnabled() && !transition) {
ret += " - ignoring invalid transition: '" + transitionName +
"'";
}
Expand Down Expand Up @@ -481,7 +481,7 @@ void WSClient::onMessage(connection_hdl hdl, client::message_ptr message)
errorCodeMessage.c_str());
}

if (switcher->verbose) {
if (VerboseLoggingEnabled()) {
blog(LOG_INFO, "client sent message:\n%s", response.c_str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool SwitcherData::checkRandom(OBSWeakSource &scene, OBSWeakSource &transition,
lastRandomScene = r.scene;
lastRandomSceneGroup = r.group;

if (verbose) {
if (VerboseLoggingEnabled()) {
r.logMatch();
}
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-screen-region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ bool SwitcherData::checkScreenRegionSwitch(OBSWeakSource &scene,
transition = s.transition;
minRegionSize = regionSize;

if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}
break;
Expand Down
4 changes: 2 additions & 2 deletions lib/legacy/switch-sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ bool SwitcherData::checkSceneSequence(OBSWeakSource &scene,
scene = s.getScene();
transition = s.transition;
setPrevSceneAfterLinger = s.usePreviousScene;
if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}
}

s.advanceActiveSequence();
if (verbose) {
if (VerboseLoggingEnabled()) {
s.logAdvanceSequence();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bool SwitcherData::checkTimeSwitch(OBSWeakSource &scene,
transition = s.transition;
match = true;

if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}
break;
Expand Down
5 changes: 3 additions & 2 deletions lib/legacy/switch-transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void SwitcherData::checkDefaultSceneTransitions()

for (auto &t : defaultSceneTransitions) {
if (t.checkMatch(currentScene)) {
if (verbose) {
if (VerboseLoggingEnabled()) {
t.logMatch();
}
t.setTransition();
Expand Down Expand Up @@ -427,7 +427,8 @@ DefTransitionSwitchWidget::DefTransitionSwitchWidget(QWidget *parent,
{
QHBoxLayout *mainLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{scenes}}", scenes}, {"{{transitions}}", transitions}};
{"{{scenes}}", scenes},
{"{{transitions}}", transitions}};
PlaceWidgets(
obs_module_text(
"AdvSceneSwitcher.transitionTab.defaultTransitionEntry"),
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bool SwitcherData::checkVideoSwitch(OBSWeakSource &scene,
match = true;
scene = s.getScene();
transition = s.transition;
if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy/switch-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ bool SwitcherData::checkWindowTitleSwitch(OBSWeakSource &scene,
}

if (match) {
if (verbose) {
if (VerboseLoggingEnabled()) {
s.logMatch();
}
break;
Expand Down
16 changes: 8 additions & 8 deletions lib/macro/macro-action-macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,32 @@ void MacroActionMacro::LogAction() const
}
switch (_action) {
case Action::PAUSE:
vblog(LOG_INFO, "paused \"%s\"", macro->Name().c_str());
ablog(LOG_INFO, "paused \"%s\"", macro->Name().c_str());
break;
case Action::UNPAUSE:
vblog(LOG_INFO, "unpaused \"%s\"", macro->Name().c_str());
ablog(LOG_INFO, "unpaused \"%s\"", macro->Name().c_str());
break;
case Action::RESET_COUNTER:
vblog(LOG_INFO, "reset counter for \"%s\"",
ablog(LOG_INFO, "reset counter for \"%s\"",
macro->Name().c_str());
break;
case Action::RUN:
vblog(LOG_INFO, "run nested macro \"%s\"",
ablog(LOG_INFO, "run nested macro \"%s\"",
macro->Name().c_str());
break;
case Action::STOP:
vblog(LOG_INFO, "stopped macro \"%s\"", macro->Name().c_str());
ablog(LOG_INFO, "stopped macro \"%s\"", macro->Name().c_str());
break;
case Action::DISABLE_ACTION:
vblog(LOG_INFO, "disabled action %d of macro \"%s\"",
ablog(LOG_INFO, "disabled action %d of macro \"%s\"",
_actionIndex.GetValue(), macro->Name().c_str());
break;
case Action::ENABLE_ACTION:
vblog(LOG_INFO, "enabled action %d of macro \"%s\"",
ablog(LOG_INFO, "enabled action %d of macro \"%s\"",
_actionIndex.GetValue(), macro->Name().c_str());
break;
case Action::TOGGLE_ACTION:
vblog(LOG_INFO, "toggled action %d of macro \"%s\"",
ablog(LOG_INFO, "toggled action %d of macro \"%s\"",
_actionIndex.GetValue(), macro->Name().c_str());
break;
default:
Expand Down
8 changes: 4 additions & 4 deletions lib/macro/macro-action-queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ void MacroActionQueue::LogAction() const
}
switch (_action) {
case Action::ADD_TO_QUEUE:
vblog(LOG_INFO, "queued actions of \"%s\" to \"%s\"",
ablog(LOG_INFO, "queued actions of \"%s\" to \"%s\"",
GetMacroName(macro.get()).c_str(),
GetActionQueueName(_queue).c_str());
break;
case Action::START_QUEUE:
vblog(LOG_INFO, "start queue \"%s\"",
ablog(LOG_INFO, "start queue \"%s\"",
GetActionQueueName(_queue).c_str());
break;
case Action::STOP_QUEUE:
vblog(LOG_INFO, "stop queue \"%s\"",
ablog(LOG_INFO, "stop queue \"%s\"",
GetActionQueueName(_queue).c_str());
break;
case Action::CLEAR_QUEUE:
vblog(LOG_INFO, "cleared queue \"%s\"",
ablog(LOG_INFO, "cleared queue \"%s\"",
GetActionQueueName(_queue).c_str());
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/macro/macro-action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool MacroAction::Load(obs_data_t *obj)

void MacroAction::LogAction() const
{
vblog(LOG_INFO, "performed action %s", GetId().c_str());
ablog(LOG_INFO, "performed action %s", GetId().c_str());
}

void MacroAction::SetEnabled(bool value)
Expand Down
4 changes: 3 additions & 1 deletion lib/switcher-data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class SwitcherData {
bool showSystemTrayNotifications = false;
bool transitionOverrideOverride = false;
bool adjustActiveTransitionType = true;
bool verbose = false;

enum class LogLevel { DEFAULT, PRINT_ACTION, VERBOSE };
LogLevel logLevel = LogLevel::DEFAULT;

/* --- End of General tab section --- */

Expand Down
7 changes: 5 additions & 2 deletions lib/utils/action-queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ void ActionQueue::RunActions()
continue;
}

vblog(LOG_INFO, "Performing action '%s' in queue '%s'",
action->GetId().c_str(), _name.c_str());
if (ActionLoggingEnabled()) {
blog(LOG_INFO, "Performing action '%s' in queue '%s'",
action->GetId().c_str(), _name.c_str());
action->LogAction();
}
action->PerformAction();
}
}
Expand Down
Loading

0 comments on commit 5cb48cb

Please sign in to comment.