Skip to content

Commit f810c63

Browse files
committed
core/command: allow log files to be specified w/ instance selectors
1 parent 19d7459 commit f810c63

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/core/main.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,23 @@ int runCommand(int argc, char** argv, QCoreApplication* coreApplication) {
239239
}
240240

241241
{
242-
auto* sub = cli.add_subcommand("log", "Read quickshell logs.");
243-
sub->add_option("--file", state.log.file, "Log file to read.")->required();
242+
auto* sub = cli.add_subcommand(
243+
"log",
244+
"Read quickshell logs.\n"
245+
"If --file is specified, the given file will be read.\n"
246+
"If not, the log of the first launched instance matching"
247+
"the instance selection flags will be read."
248+
);
249+
250+
auto* file = sub->add_option("--file", state.log.file, "Log file to read.");
244251

245252
sub->add_option("-r,--rules", state.log.readoutRules, "Log file to read.")
246253
->description("Rules to apply to the log being read, in the format of QT_LOGGING_RULES.");
247254

255+
auto* instance = addInstanceSelection(sub)->excludes(file);
256+
addConfigSelection(sub)->excludes(instance)->excludes(file);
248257
addLoggingOptions(sub, false);
249258

250-
// todo
251-
// addConfigSelection(sub)->excludes(file);
252-
253259
state.subcommand.log = sub;
254260
}
255261

@@ -444,9 +450,19 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance) {
444450
}
445451

446452
int readLogFile(CommandState& cmd) {
447-
auto file = QFile(*cmd.log.file);
453+
auto path = *cmd.log.file;
454+
455+
if (path.isEmpty()) {
456+
InstanceLockInfo instance;
457+
auto r = selectInstance(cmd, &instance);
458+
if (r != 0) return r;
459+
460+
path = QDir(QsPaths::basePath(instance.instance.instanceId)).filePath("log.qslog");
461+
}
462+
463+
auto file = QFile(path);
448464
if (!file.open(QFile::ReadOnly)) {
449-
qCCritical(logBare) << "Failed to open log file" << *cmd.log.file;
465+
qCCritical(logBare) << "Failed to open log file" << path;
450466
return -1;
451467
}
452468

0 commit comments

Comments
 (0)