Skip to content

Commit

Permalink
Add log filter
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim.zhemerenko committed Feb 22, 2024
1 parent 9a146be commit fea4da4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 41 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: '21.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn && yarn build
- run: yarn publish
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
21
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spryrocks/capacitor-ionic-core-plugin",
"version": "5.7.0-alpha.0",
"version": "5.8.0-alpha.6",
"description": "Ionic plugin core capacitor",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand All @@ -26,7 +26,7 @@
"compile": "tsc --noEmit"
},
"dependencies": {
"@spryrocks/logger-plugin": "^0.1.15-alpha.1"
"@spryrocks/logger-plugin": "^0.1.17-alpha.2"
},
"peerDependencies": {
"@capacitor/core": "^5.4.0"
Expand Down
23 changes: 19 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createLoggerFactory,
GlobalData,
ILoggerObserver,
LogData,
LoggerObserver,
prepareLogData,
} from './logger';
Expand All @@ -32,6 +33,7 @@ type LogEvent = {

export interface ICapacitorPlugin {
get logObserver(): ILoggerObserver;
setLogLevels(logLevels: LogLevel[] | undefined): Promise<void>;
}

export type PluginOptions<TDefinitions extends IDefinitions> = {
Expand All @@ -49,13 +51,15 @@ export abstract class CapacitorPlugin<

private readonly _logObserver = new LoggerObserver();

private readonly _logNotifiers = new MultipleNotifiers([
this._logObserver,
CapacitorPlugin._logObserver,
]);
private readonly _logNotifiers = new MultipleNotifiers({
notifiers: [this._logObserver, CapacitorPlugin._logObserver],
filter: this.testLog.bind(this),
});

private readonly _loggerFactory: ILoggerFactory<GlobalData>;

private logLevels: LogLevel[] | undefined;

protected abstract readonly mappers: TMappers;

// noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
Expand Down Expand Up @@ -136,6 +140,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);
});
Expand Down Expand Up @@ -208,4 +213,14 @@ export abstract class CapacitorPlugin<
public get proxy() {
return this.options.proxy;
}

public async setLogLevels(logLevels: LogLevel[] | undefined) {
this.logLevels = logLevels;
}

private testLog(data: LogData) {
const logLevels = this.logLevels;
if (!logLevels) return true;
return logLevels.includes(data.level);
}
}
62 changes: 31 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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.17-alpha.0":
version "0.1.17-alpha.0"
resolved "https://registry.yarnpkg.com/@spryrocks/logger-core/-/logger-core-0.1.17-alpha.0.tgz#574b1231b633586bdd829f6bb0b5880b2a317167"
integrity sha512-m2vY5EhOv8rz8vyIh0agioKm5W/ETMvq0gmAEM+Jg2V8ciK+UTyT7dAkXnZelscuaB+tLDWqS/J2cnaNhQc2lA==

"@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.17-alpha.2":
version "0.1.17-alpha.2"
resolved "https://registry.yarnpkg.com/@spryrocks/logger-observer/-/logger-observer-0.1.17-alpha.2.tgz#7089773ffb422a2e95d1a5edd6ce1e1ab1eb3a01"
integrity sha512-NlrVcCTOhTXaheye3U6dyhlqoN3SkZVQycBZJ5r4oqiL3ziiTAjTJ/DRS4PiwixE1yugaUfKZW02o5cQ41RqNQ==
dependencies:
"@spryrocks/logger-core" "^0.1.15-alpha.0"
"@spryrocks/logger-core" "^0.1.17-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.17-alpha.0":
version "0.1.17-alpha.0"
resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin-core/-/logger-plugin-core-0.1.17-alpha.0.tgz#84fb20f978a00219f732c7615109a01ee98522e8"
integrity sha512-bgQcfWn+eYpff1Gsof/Pm8aQchZhBhm4ctKh9c4otkwpOVvW6ob3guyUBkV/xAeEzdPdeYTtqSBiOB2xzvVRsw==
dependencies:
"@spryrocks/logger-core" "^0.1.15-alpha.0"
"@spryrocks/logger-core" "^0.1.17-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.17-alpha.2":
version "0.1.17-alpha.2"
resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin-observer/-/logger-plugin-observer-0.1.17-alpha.2.tgz#64d2f59a449e988a4fe70ef402ed458c2675e0c8"
integrity sha512-veZXAEQy0txmMCMOAr0nB4E3fN1Qa9waGcM5VUW9Rzq2/3NLQXPGCu1DTjVRSktbCbf7BgQOlqHWXlBRrd9qCw==
dependencies:
"@spryrocks/logger-observer" "^0.1.15-alpha.0"
"@spryrocks/logger-plugin-core" "^0.1.15-alpha.0"
"@spryrocks/logger-observer" "^0.1.17-alpha.2"
"@spryrocks/logger-plugin-core" "^0.1.17-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.17-alpha.2":
version "0.1.17-alpha.2"
resolved "https://registry.yarnpkg.com/@spryrocks/logger-plugin/-/logger-plugin-0.1.17-alpha.2.tgz#12662d43e9f2ffb5d0ad87e351408bdfbed997e7"
integrity sha512-meq63XwkpMv9LdIsoOxIby1bi8BciSd3dAo60sD0dLB9FeB7GDP38FAYsSi09sN7+FxZq5uqn8Ug7TYk+Fdxdg==
dependencies:
"@spryrocks/logger" "^0.1.15-alpha.1"
"@spryrocks/logger-plugin-observer" "^0.1.15-alpha.0"
"@spryrocks/logger" "^0.1.17-alpha.2"
"@spryrocks/logger-plugin-observer" "^0.1.17-alpha.2"

"@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.17-alpha.2":
version "0.1.17-alpha.2"
resolved "https://registry.yarnpkg.com/@spryrocks/logger/-/logger-0.1.17-alpha.2.tgz#c02ecf89eb57f1f7680852110055181f5cebd32b"
integrity sha512-HRVz+JDqAQ0N8D9rp93tV3gGyhwN6ZdI2vBWKftgXPCd0cle/GkSL3Wjj8P3F6kNcky2/xv0dyROGWIcLQoxSQ==
dependencies:
"@spryrocks/logger-observer" "^0.1.15-alpha.0"
"@spryrocks/logger-observer" "^0.1.17-alpha.2"

"@spryrocks/prettier-config@^0.3.0-alpha.0":
version "0.3.0-alpha.0"
Expand Down

0 comments on commit fea4da4

Please sign in to comment.