[geary/mjog/logging-improvements: 9/23] Geary.Logging: Enable API clients to suppress DEBUG logging per-domain
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/logging-improvements: 9/23] Geary.Logging: Enable API clients to suppress DEBUG logging per-domain
- Date: Thu, 16 Apr 2020 09:03:24 +0000 (UTC)
commit 718f02bd8a94bf20fbd5af47d60aba8fd6f040b0
Author: Michael Gratton <mike vee net>
Date: Wed Apr 15 16:51:07 2020 +1000
Geary.Logging: Enable API clients to suppress DEBUG logging per-domain
src/engine/api/geary-logging.vala | 12 +++++++-----
src/engine/util/util-logging.vala | 37 ++++++++++++++++++++++++++++++++++---
2 files changed, 41 insertions(+), 8 deletions(-)
---
diff --git a/src/engine/api/geary-logging.vala b/src/engine/api/geary-logging.vala
index dcdfd76c..d0f8b349 100644
--- a/src/engine/api/geary-logging.vala
+++ b/src/engine/api/geary-logging.vala
@@ -359,6 +359,7 @@ private unowned FileStream? stream = null;
public void init() {
if (init_count++ != 0)
return;
+ Logging.suppressed_domains = new Gee.HashSet<string>();
record_lock = GLib.Mutex();
writer_lock = GLib.Mutex();
max_log_length = DEFAULT_MAX_LOG_BUFFER_LENGTH;
@@ -571,12 +572,13 @@ public GLib.LogWriterOutput default_log_writer(GLib.LogLevelFlags levels,
}
private bool should_blacklist(Record record) {
+ const string DOMAIN_PREFIX = Logging.DOMAIN + ".";
return (
- // GdkPixbuf spams us e.g. when window focus changes,
- // including between MainWindow and the Inspector, which is
- // very annoying.
- (record.levels == GLib.LogLevelFlags.LEVEL_DEBUG &&
- record.domain == "GdkPixbuf") ||
+ // Don't need to check for the engine's domains, they were
+ // already handled by Source's methods.
+ (record.domain != Logging.DOMAIN &&
+ !record.domain.has_prefix(DOMAIN_PREFIX) &&
+ record.domain in Logging.suppressed_domains) ||
// GAction does not support disabling parameterised actions
// with specific values, but GTK complains if the parameter is
// set to null to achieve the same effect, and they aren't
diff --git a/src/engine/util/util-logging.vala b/src/engine/util/util-logging.vala
index 9afa8cc8..5fd90403 100644
--- a/src/engine/util/util-logging.vala
+++ b/src/engine/util/util-logging.vala
@@ -7,6 +7,35 @@
*/
+namespace Geary.Logging {
+
+
+ internal Gee.Set<string> suppressed_domains;
+
+
+ /**
+ * Suppresses debug logging for a given logging domain.
+ *
+ * If a logging domain is suppressed, DEBUG-level logging will not
+ * be sent to the logging system.
+ *
+ * @see unsuppress_domain
+ */
+ public void suppress_domain(string domain) {
+ Logging.suppressed_domains.add(domain);
+ }
+
+ /**
+ * Un-suppresses debug logging for a given logging domain.
+ *
+ * @see suppress_domain
+ */
+ public void unsuppress_domain(string domain) {
+ Logging.suppressed_domains.remove(domain);
+ }
+
+}
+
/**
* Mixin interface for objects that support structured logging.
*
@@ -167,9 +196,11 @@ public interface Geary.Logging.Source : GLib.Object {
*/
[PrintfFormat]
public inline void debug(string fmt, ...) {
- log_structured(
- this.logging_flags, LogLevelFlags.LEVEL_DEBUG, fmt, va_list()
- );
+ if (!(this.logging_domain in Logging.suppressed_domains)) {
+ log_structured(
+ this.logging_flags, LogLevelFlags.LEVEL_DEBUG, fmt, va_list()
+ );
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]