1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Debug] Add a '-log' flag.

This commit is contained in:
Dave Davenport 2022-07-08 22:53:07 +02:00
parent f3634d4ff3
commit 96027decd9
4 changed files with 53 additions and 4 deletions

View file

@ -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

View file

@ -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:

View file

@ -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.

View file

@ -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) {