summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2022-07-08 22:53:07 +0200
committerDave Davenport <qball@blame.services>2022-07-08 22:53:07 +0200
commit96027decd9100d72d5aeac10682cb45e9c74005e (patch)
treec48627f27c76050524340e811e38411aeefdd441
parentf3634d4ff3e3f174130bd9a2f5374a6c2713b160 (diff)
[Debug] Add a '-log' flag.
-rw-r--r--INSTALL.md2
-rw-r--r--doc/rofi-debugging.516
-rw-r--r--doc/rofi-debugging.5.markdown11
-rw-r--r--source/rofi.c28
4 files changed, 53 insertions, 4 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 8bcef0de..7af5e761 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -28,7 +28,7 @@ You can also use [Meson](https://mesonbuild.com/) as an alternative.
* libpangocairo
* libcairo
* libcairo-xcb
-* libglib2.0 >= 2.40
+* libglib2.0 >= 2.68
* gmodule-2.0
* gio-unix-2.0
* libgdk-pixbuf-2.0
diff --git a/doc/rofi-debugging.5 b/doc/rofi-debugging.5
index 747d1fd0..dc0eb01b 100644
--- a/doc/rofi-debugging.5
+++ b/doc/rofi-debugging.5
@@ -175,6 +175,22 @@ For full list see \fB\fCman rofi\fR\&.
.PP
Example: \fB\fCG_MESSAGES_DEBUG=Dialogs.DRun rofi -show drun\fR To get specific output from the Desktop file run dialog.
+.PP
+To redirect the debug output to a file (\fB\fC~/rofi.log\fR) add:
+
+.PP
+.RS
+
+.nf
+rofi -show drun -log ~/rofi.log
+
+.fi
+.RE
+
+.PP
+Specifying the logfile automatically enabled all log domains.
+This can be useful when rofi is launched from a window manager.
+
.SH Creating a backtrace.
.PP
First make sure you compile \fBrofi\fP with debug symbols:
diff --git a/doc/rofi-debugging.5.markdown b/doc/rofi-debugging.5.markdown
index f9a1012a..643c68b1 100644
--- a/doc/rofi-debugging.5.markdown
+++ b/doc/rofi-debugging.5.markdown
@@ -128,7 +128,16 @@ environment variable. At the time of creation of this page, the following debug
For full list see `man rofi`.
-Example: ```G_MESSAGES_DEBUG=Dialogs.DRun rofi -show drun``` To get specific output from the Desktop file run dialog.
+Example: `G_MESSAGES_DEBUG=Dialogs.DRun rofi -show drun` To get specific output from the Desktop file run dialog.
+
+To redirect the debug output to a file (`~/rofi.log`) add:
+
+```
+rofi -show drun -log ~/rofi.log
+```
+
+Specifying the logfile automatically enabled all log domains.
+This can be useful when rofi is launched from a window manager.
## Creating a backtrace.
diff --git a/source/rofi.c b/source/rofi.c
index 69058d1a..4d40b1cd 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -771,6 +771,13 @@ static gboolean record(G_GNUC_UNUSED void *data) {
rofi_capture_screenshot();
return G_SOURCE_CONTINUE;
}
+static void rofi_custom_log_function(const char *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data) {
+ int fp = GPOINTER_TO_INT(user_data);
+ dprintf(fp, "[%s]: %s\n", log_domain == NULL ? "default" : log_domain,
+ message);
+}
/**
* @param argc number of input arguments.
* @param argv array of the input arguments.
@@ -780,9 +787,26 @@ static gboolean record(G_GNUC_UNUSED void *data) {
* @returns return code of rofi.
*/
int main(int argc, char *argv[]) {
- TIMINGS_START();
-
cmd_set_arguments(argc, argv);
+ if (find_arg("-log") >= 0) {
+ char *logfile = NULL;
+ find_arg_str("-log", &logfile);
+ if (logfile != NULL) {
+ int fp = open(logfile, O_CLOEXEC | O_APPEND | O_CREAT | O_WRONLY,
+ S_IRUSR | S_IWUSR);
+ if (fp != -1) {
+ g_log_set_default_handler(rofi_custom_log_function,
+ GINT_TO_POINTER(fp));
+
+ } else {
+ g_error("Failed to open logfile '%s': %s.", logfile, strerror(errno));
+ }
+
+ } else {
+ g_warning("Option '-log' should pass in a filename.");
+ }
+ }
+ TIMINGS_START();
// Version
if (find_arg("-v") >= 0 || find_arg("-version") >= 0) {