Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4e313a1

Browse files
committed
Add optional log handler to fl_test_gtk_logs
1 parent c7e7b62 commit 4e313a1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

shell/platform/linux/testing/fl_test_gtk_logs.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,35 @@ namespace testing {
1111
namespace {
1212

1313
bool gtk_initialized = false;
14+
GLogWriterFunc log_writer_cb = nullptr;
1415
GLogLevelFlags fl_received_log_levels = (GLogLevelFlags)0x0;
1516

1617
GLogWriterOutput log_writer(GLogLevelFlags log_level,
1718
const GLogField* fields,
1819
gsize n_fields,
1920
gpointer user_data) {
2021
fl_received_log_levels = (GLogLevelFlags)(log_level | fl_received_log_levels);
21-
return g_log_writer_default(log_level, fields, n_fields, user_data);
22+
if (log_writer_cb == nullptr) {
23+
return g_log_writer_default(log_level, fields, n_fields, user_data);
24+
}
25+
GLogWriterOutput result =
26+
log_writer_cb(log_level, fields, n_fields, user_data);
27+
if (result != G_LOG_WRITER_HANDLED) {
28+
return g_log_writer_default(log_level, fields, n_fields, user_data);
29+
}
30+
return result;
2231
}
2332

2433
} // namespace
2534

26-
void fl_ensure_gtk_init() {
35+
void fl_ensure_gtk_init(GLogWriterFunc writer) {
2736
if (!gtk_initialized) {
2837
gtk_init(0, nullptr);
2938
g_log_set_writer_func(log_writer, nullptr, nullptr);
3039
gtk_initialized = true;
3140
}
3241
fl_reset_received_gtk_log_levels();
42+
log_writer_cb = writer;
3343
}
3444

3545
void fl_reset_received_gtk_log_levels() {

shell/platform/linux/testing/fl_test_gtk_logs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ namespace testing {
1919
* To retrieve the bitfield of recorded log levels, use
2020
* `fl_get_received_gtk_log_levels()`.
2121
*
22+
* @param[in] writer The custom log writer function to use. If `nullptr`, the
23+
* default log writer function will be used.
24+
*
2225
* @brief Ensures that GTK has been initialized and starts monitoring logs.
2326
*/
24-
void fl_ensure_gtk_init();
27+
void fl_ensure_gtk_init(GLogWriterFunc writer = nullptr);
2528

2629
/**
2730
* Resets the recorded GTK log levels to zero.

0 commit comments

Comments
 (0)