From ab26917b8023fb5ce423b44a4d4e1681e1e70be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Cla=C3=9Fen?= Date: Thu, 8 Feb 2024 10:41:55 +0100 Subject: [PATCH] Make the logger more configurable (#1471) --- extension-manifest-v2/package.json | 2 +- extension-manifest-v3/package.json | 2 +- .../src/background/reporting/index.js | 21 ++++++++++++++++++- package-lock.json | 10 ++++----- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/extension-manifest-v2/package.json b/extension-manifest-v2/package.json index d40f01eb3..45487dd3a 100644 --- a/extension-manifest-v2/package.json +++ b/extension-manifest-v2/package.json @@ -45,7 +45,7 @@ "@ghostery/trackers-preview": "^1.0.0", "@ghostery/ui": "^1.0.0", "@sentry/browser": "7.1.1", - "@whotracksme/webextension-packages": "^5.0.1", + "@whotracksme/webextension-packages": "^5.0.2", "classnames": "^2.3.2", "d3": "^7.8.5", "foundation-sites": "^6.6.2", diff --git a/extension-manifest-v3/package.json b/extension-manifest-v3/package.json index b5bb60c4e..e83afe53b 100644 --- a/extension-manifest-v3/package.json +++ b/extension-manifest-v3/package.json @@ -38,7 +38,7 @@ "@ghostery/trackers-preview": "^1.0.0", "@ghostery/ui": "^1.0.0", "@github/relative-time-element": "^4.3.0", - "@whotracksme/webextension-packages": "^5.0.1", + "@whotracksme/webextension-packages": "^5.0.2", "hybrids": "^8.2.5", "idb": "^7.1.1", "jwt-decode": "^4.0.0", diff --git a/extension-manifest-v3/src/background/reporting/index.js b/extension-manifest-v3/src/background/reporting/index.js index 58585b0b9..24dc03cea 100644 --- a/extension-manifest-v3/src/background/reporting/index.js +++ b/extension-manifest-v3/src/background/reporting/index.js @@ -18,6 +18,7 @@ import { UrlReporter, RequestReporter, setLogLevel, + describeLoggers, } from '@whotracksme/webextension-packages/packages/reporting'; import { getBrowserInfo } from '@ghostery/libs'; @@ -33,7 +34,21 @@ const webRequestPipeline = new WebRequestPipeline(); // Important to call it in a first tick as it assigns chrome. listeners webRequestPipeline.init(); -setLogLevel('debug'); +(async () => { + try { + const key = 'ghosteryReportingLoggerConfig'; + const { [key]: config } = (await chrome.storage.local.get(key)) || {}; + if (config) { + for (const { level, prefix = '*' } of config) { + setLogLevel(level, { prefix }); + } + } else { + setLogLevel('off'); + } + } catch (e) { + console.warn('Failed to apply logger overwrites', e); + } +})(); function platformSpecificSettings() { if ( @@ -261,4 +276,8 @@ globalThis.ghostery.WTM = { config, webRequestPipeline, extensionStartedAt: new Date(), + logging: { + setLogLevel, + describeLoggers, + }, }; diff --git a/package-lock.json b/package-lock.json index faf971c77..117e9ba62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "@ghostery/trackers-preview": "^1.0.0", "@ghostery/ui": "^1.0.0", "@sentry/browser": "7.1.1", - "@whotracksme/webextension-packages": "^5.0.1", + "@whotracksme/webextension-packages": "^5.0.2", "classnames": "^2.3.2", "d3": "^7.8.5", "foundation-sites": "^6.6.2", @@ -117,7 +117,7 @@ "@ghostery/trackers-preview": "^1.0.0", "@ghostery/ui": "^1.0.0", "@github/relative-time-element": "^4.3.0", - "@whotracksme/webextension-packages": "^5.0.1", + "@whotracksme/webextension-packages": "^5.0.2", "hybrids": "^8.2.5", "idb": "^7.1.1", "jwt-decode": "^4.0.0", @@ -3820,9 +3820,9 @@ } }, "node_modules/@whotracksme/webextension-packages": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@whotracksme/webextension-packages/-/webextension-packages-5.0.1.tgz", - "integrity": "sha512-vkqZNExBX38o4hix58zaA9DdfxN4pQDHCkEu4qpd4kHnxXwKjvLx97UiwMWeayH9SwKUlklzBnaxHEfuZU4W+Q==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@whotracksme/webextension-packages/-/webextension-packages-5.0.2.tgz", + "integrity": "sha512-yY49eLkn3taPU4vqk0DCl21odQFZPbVIzgZsfGPPLC6FYZIIy61p12bWxTQQmuDEo+TDXiJ6MO5BSTuevznIhQ==", "dependencies": { "@cliqz/url-parser": "^1.1.5", "date-fns": "^2.29.3",