From ea6761c9a00edf6c515b2ba4a947ad7eb8ab8de6 Mon Sep 17 00:00:00 2001 From: "maksim.zhemerenko" Date: Wed, 21 Feb 2024 23:52:41 +0100 Subject: [PATCH] Add log filter --- .github/workflows/gradle-publish.yml | 2 +- .nvmrc | 2 +- package.json | 4 +- src/plugin.ts | 44 ++++++++++++-------- yarn.lock | 62 ++++++++++++++-------------- 5 files changed, 62 insertions(+), 52 deletions(-) diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index cc0cd4b..0af1a63 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -12,7 +12,7 @@ jobs: # Setup .npmrc file to publish to npm - uses: actions/setup-node@v3 with: - node-version: '20.x' + node-version: '21.x' registry-url: 'https://registry.npmjs.org' - run: yarn && yarn build - run: yarn publish diff --git a/.nvmrc b/.nvmrc index 209e3ef..aabe6ec 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -20 +21 diff --git a/package.json b/package.json index 1cf69bc..c66c435 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spryrocks/capacitor-ionic-core-plugin", - "version": "5.7.0-alpha.0", + "version": "5.8.0-alpha.0", "description": "Ionic plugin core capacitor", "main": "dist/plugin.cjs.js", "module": "dist/esm/index.js", @@ -26,7 +26,7 @@ "compile": "tsc --noEmit" }, "dependencies": { - "@spryrocks/logger-plugin": "^0.1.15-alpha.1" + "@spryrocks/logger-plugin": "^0.1.16-alpha.1" }, "peerDependencies": { "@capacitor/core": "^5.4.0" diff --git a/src/plugin.ts b/src/plugin.ts index 747edb2..a18ef1e 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -15,6 +15,8 @@ import { import { ErrorLevel, ILoggerFactory, + ILoggerFilters, + LoggerFilters, LogLevel, LogParams, MultipleNotifiers, @@ -32,6 +34,7 @@ type LogEvent = { export interface ICapacitorPlugin { get logObserver(): ILoggerObserver; + get logFilters(): ILoggerFilters; } export type PluginOptions = { @@ -56,6 +59,8 @@ export abstract class CapacitorPlugin< private readonly _loggerFactory: ILoggerFactory; + private readonly _logFilters = new LoggerFilters(); + protected abstract readonly mappers: TMappers; // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected @@ -136,6 +141,7 @@ export abstract class CapacitorPlugin< ) { try { this.proxy.addListener(name, (event) => { + // eslint-disable-next-line no-console console.log('CapacitorPlugin', 'event received', name, event); listener(event as TListener); }); @@ -164,23 +170,23 @@ export abstract class CapacitorPlugin< } private processLogEventReceived(event: LogEvent) { - this._logNotifiers.notify( - prepareLogData({ - data: { - tag: event.tag, - message: event.message, - params: event.params, - level: event.level, - error: undefined, - errorLevel: ErrorLevel.Medium, - }, - globalData: { - plugin: this.options.pluginLogName, - action: event.action, - isNative: true, - }, - }), - ); + const data = prepareLogData({ + data: { + tag: event.tag, + message: event.message, + params: event.params, + level: event.level, + error: undefined, + errorLevel: ErrorLevel.Medium, + }, + globalData: { + plugin: this.options.pluginLogName, + action: event.action, + isNative: true, + }, + }); + if (!this._logFilters.test(data)) return; + this._logNotifiers.notify(data); } // private isPluginAvailableInCapacitor() { @@ -205,6 +211,10 @@ export abstract class CapacitorPlugin< return this._logObserver; } + public get logFilters(): ILoggerFilters { + return this._logFilters; + } + public get proxy() { return this.options.proxy; } diff --git a/yarn.lock b/yarn.lock index 049c8ca..51183ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -129,47 +129,47 @@ eslint-plugin-import "^2.28.1" eslint-plugin-prettier "^5.0.0" -"@spryrocks/logger-core@^0.1.15-alpha.0": - version "0.1.15-alpha.0" - resolved "https://registry.yarnpkg.com/@spryrocks/logger-core/-/logger-core-0.1.15-alpha.0.tgz#c8c8f8f802ace92683e930b2918587bd30bb61ba" - integrity sha512-B+MfnTVMg8XsShJOLnXhJvmSc5/26tHRDyUvzfuw4MsAS4ME8vZuU/+tcyG/m+H8PbRDv5CE9Qmg0dwUFlk4EQ== +"@spryrocks/logger-core@^0.1.16-alpha.0": + version "0.1.16-alpha.0" + resolved "https://registry.yarnpkg.com/@spryrocks/logger-core/-/logger-core-0.1.16-alpha.0.tgz#184c9c285b50f80faeea687ba58d1713f126b5b2" + integrity sha512-LyNCmNFF++//9W2cxXzzQuJfbqHeSKUsGZT9253UD18yTeZYgmoPjpetFDy12UJVzNCjKVAV1gao3zBY4pDh0g== -"@spryrocks/logger-observer@^0.1.15-alpha.0": - version "0.1.15-alpha.0" - resolved "https://registry.yarnpkg.com/@spryrocks/logger-observer/-/logger-observer-0.1.15-alpha.0.tgz#9b406ef3e187a728fa867ffb770c39f32316c3d8" - integrity sha512-fz6Ls4KZRL2ZasrnTY8223R7KIjZ7pyy8W9HduwdY1jprgg13+qvGe52GFHDionA6pYeaYc8J1/rZ5wjYrvvUA== +"@spryrocks/logger-observer@^0.1.16-alpha.0": + version "0.1.16-alpha.0" + resolved "https://registry.yarnpkg.com/@spryrocks/logger-observer/-/logger-observer-0.1.16-alpha.0.tgz#34360d3a51fee978027c9b239e3014b0e2a44817" + integrity sha512-P8I4QJXQu5Hn4zdGfsUa1PqMEBNeFtEWB4X9UwqEZip8SGY4ovbk7VgguxALibFVW3jcahNrN3e9kkcKqBqG4Q== dependencies: - "@spryrocks/logger-core" "^0.1.15-alpha.0" + "@spryrocks/logger-core" "^0.1.16-alpha.0" -"@spryrocks/logger-plugin-core@^0.1.15-alpha.0": - version "0.1.15-alpha.0" - resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin-core/-/logger-plugin-core-0.1.15-alpha.0.tgz#e42f202dd57bb4d1627bfed514da8d6aa69244d5" - integrity sha512-iRmip/fa+V/IWxr2H3yHcg4YJmoRUOgqUv0Qvol7dcDK21pF9NasFJVJrMRXoGqhv3S6CI/AHRIhNx1idQ9lSw== +"@spryrocks/logger-plugin-core@^0.1.16-alpha.0": + version "0.1.16-alpha.0" + resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin-core/-/logger-plugin-core-0.1.16-alpha.0.tgz#1cfe699b0bd5f7c5759bec463ae84c1b567439af" + integrity sha512-/lo2TE0W6o5F7PEgFGB3Z9DPZc6Pr7zCzq001NG4ExLzvbGmOj55M1X5rMq4RfupSQww4G+6LzoVHAfNVXlDpg== dependencies: - "@spryrocks/logger-core" "^0.1.15-alpha.0" + "@spryrocks/logger-core" "^0.1.16-alpha.0" -"@spryrocks/logger-plugin-observer@^0.1.15-alpha.0": - version "0.1.15-alpha.0" - resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin-observer/-/logger-plugin-observer-0.1.15-alpha.0.tgz#06ffa53a7f2b2660cae018970abdd87f8dcd395c" - integrity sha512-H5qaNFbSWHL8Lpkf57wGisYlpQ+Wj548vG/Evb47xK9xASVlqctc5PLmCQu1iCoonmzsxMPUv80CX/KcrMciKw== +"@spryrocks/logger-plugin-observer@^0.1.16-alpha.0": + version "0.1.16-alpha.0" + resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin-observer/-/logger-plugin-observer-0.1.16-alpha.0.tgz#0f0d6f41c8937ddd961f381cd63d74f06356d40a" + integrity sha512-bms3kQwT4RcnMQVS8q8eYeYh0owfPZJlQwL6kWvZUGJ665PPg3LDuF9k5qUTx+c3vTNbhQaTXp7koyCe6sqh8Q== dependencies: - "@spryrocks/logger-observer" "^0.1.15-alpha.0" - "@spryrocks/logger-plugin-core" "^0.1.15-alpha.0" + "@spryrocks/logger-observer" "^0.1.16-alpha.0" + "@spryrocks/logger-plugin-core" "^0.1.16-alpha.0" -"@spryrocks/logger-plugin@^0.1.15-alpha.1": - version "0.1.15-alpha.1" - resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin/-/logger-plugin-0.1.15-alpha.1.tgz#dd03b5b85642e24b6f85ed55e0b6b984ab384a39" - integrity sha512-hUzBeJel8zLmN4q7wldq7Wlj804ljpA98juop53EhyYn99c756CAIfdim7nSyXMBlGGltb7wf8p+S413QYkSQg== +"@spryrocks/logger-plugin@^0.1.16-alpha.1": + version "0.1.16-alpha.1" + resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin/-/logger-plugin-0.1.16-alpha.1.tgz#a9305486b5c76b5bf5cac68d3262bf756f1ba2a4" + integrity sha512-UUVSR52qbr+DzacmFum4gowNGn1W0oRwsFU2dPB2KVrBJmxn4rlng18peLng1kKGGGU1pgSJ0UnVSHfLIFVONw== dependencies: - "@spryrocks/logger" "^0.1.15-alpha.1" - "@spryrocks/logger-plugin-observer" "^0.1.15-alpha.0" + "@spryrocks/logger" "^0.1.16-alpha.1" + "@spryrocks/logger-plugin-observer" "^0.1.16-alpha.0" -"@spryrocks/logger@^0.1.15-alpha.1": - version "0.1.15-alpha.1" - resolved "https://registry.yarnpkg.com/@spryrocks/logger/-/logger-0.1.15-alpha.1.tgz#66e80ee4283fcf96aca7285cb23ac26881bf739d" - integrity sha512-2iWn8cX3P7veezkkaro/IDUKYf/q3KRp/nBdnkpcR8y+VXxLsNRhptq2BY1LVXJhpoXbEE1kRbTy/5dJ0Uq7jA== +"@spryrocks/logger@^0.1.16-alpha.1": + version "0.1.16-alpha.1" + resolved "https://registry.yarnpkg.com/@spryrocks/logger/-/logger-0.1.16-alpha.1.tgz#b644c08f8baca88248243156d8db18e564c9fcde" + integrity sha512-+Maah+rYnWnmwsvm+PKNL10MtQ2mx+Mj3wFjc8zTA8TK2KtLOnflGST2RjUn+3LCL5vAnESkT24Q5VowZZvNdQ== dependencies: - "@spryrocks/logger-observer" "^0.1.15-alpha.0" + "@spryrocks/logger-observer" "^0.1.16-alpha.0" "@spryrocks/prettier-config@^0.3.0-alpha.0": version "0.3.0-alpha.0"