Skip to content

Commit 5ceaae2

Browse files
committed
Do not use log_structured!
This removes redundant file, line, and function fields. Fixes #1537
1 parent a09e9fa commit 5ceaae2

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

glib/src/bridged_logging.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3-
use crate::{log as glib_log, translate::*};
3+
use crate::{gstr, log as glib_log, log_structured_array, translate::*, LogField};
44

55
// rustdoc-stripper-ignore-next
66
/// Enumeration of the possible formatting behaviours for a
@@ -143,17 +143,25 @@ impl GlibLogger {
143143
) {
144144
let line = line.map(|l| l.to_string());
145145
let line = line.as_deref();
146-
147-
crate::log_structured!(
148-
domain.unwrap_or("default"),
149-
GlibLogger::level_to_glib(level),
150-
{
151-
"CODE_FILE" => file.unwrap_or("<unknown file>");
152-
"CODE_LINE" => line.unwrap_or("<unknown line>");
153-
"CODE_FUNC" => func.unwrap_or("<unknown module path>");
154-
"MESSAGE" => message;
155-
}
156-
);
146+
let glib_level = GlibLogger::level_to_glib(level);
147+
let fields = [
148+
LogField::new(gstr!("PRIORITY"), glib_level.priority().as_bytes()),
149+
LogField::new(
150+
gstr!("CODE_FILE"),
151+
file.unwrap_or("<unknown file>").as_bytes(),
152+
),
153+
LogField::new(
154+
gstr!("CODE_LINE"),
155+
line.unwrap_or("<unknown line>").as_bytes(),
156+
),
157+
LogField::new(
158+
gstr!("CODE_FUNC"),
159+
func.unwrap_or("<unknown module path>").as_bytes(),
160+
),
161+
LogField::new(gstr!("MESSAGE"), message.as_bytes()),
162+
LogField::new(gstr!("GLIB_DOMAIN"), domain.unwrap_or("default").as_bytes()),
163+
];
164+
log_structured_array(glib_level, &fields);
157165
}
158166
}
159167

glib/tests/bridged_logging.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ fn glib_logger_formats() {
103103
level: glib::LogLevel::Info,
104104
fields: vec![
105105
("PRIORITY".to_string(), Some("6".to_string())),
106-
(
107-
"CODE_FILE".to_string(),
108-
Some("glib/src/bridged_logging.rs".to_string())
109-
),
110-
("CODE_LINE".to_string(), Some("147".to_string())),
111-
(
112-
"CODE_FUNC".to_string(),
113-
Some("glib::bridged_logging::GlibLogger::write_log_structured".to_string())
114-
),
115106
(
116107
"CODE_FILE".to_string(),
117108
Some("/path/to/a/test/file.rs".to_string())

0 commit comments

Comments
 (0)