@loglayer/plugin-filter 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,162 +1,199 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/FilterExecutor.ts
2
- var _jsonquery = require('@jsonquerylang/jsonquery');
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let __jsonquerylang_jsonquery = require("@jsonquerylang/jsonquery");
25
+ __jsonquerylang_jsonquery = __toESM(__jsonquerylang_jsonquery);
26
+
27
+ //#region src/FilterExecutor.ts
28
+ /**
29
+ * Core filtering logic implementation.
30
+ * Handles pattern matching and query-based filtering of log messages.
31
+ *
32
+ * @internal
33
+ */
3
34
  var FilterExecutor = class {
4
-
5
-
6
- /**
7
- * Creates a new FilterExecutor instance.
8
- *
9
- * @param config - The filter plugin configuration
10
- */
11
- constructor(config) {
12
- this.config = config;
13
- this.context = {
14
- message: "",
15
- logLevel: "",
16
- data: {},
17
- debugItems: []
18
- };
19
- }
20
- /**
21
- * Resets the context for a new log message check.
22
- *
23
- * @param params - The log message parameters
24
- */
25
- resetContext(params) {
26
- this.context = {
27
- message: _optionalChain([params, 'access', _ => _.messages, 'optionalAccess', _2 => _2.join, 'call', _3 => _3(" ")]) || "",
28
- logLevel: params.logLevel,
29
- data: params.data || {},
30
- debugItems: ["[filter-plugin] ================================="]
31
- };
32
- }
33
- /**
34
- * Prints debug information if debug mode is enabled.
35
- */
36
- printDebugItems() {
37
- if (this.config.debug) {
38
- for (const item of this.context.debugItems) {
39
- console.log(item);
40
- }
41
- }
42
- }
43
- /**
44
- * Checks if the current message matches any of the configured patterns.
45
- * Supports both string and RegExp patterns.
46
- *
47
- * @returns true if any pattern matches, false otherwise
48
- */
49
- checkMessagePatterns() {
50
- if (!_optionalChain([this, 'access', _4 => _4.config, 'access', _5 => _5.messages, 'optionalAccess', _6 => _6.length])) {
51
- return false;
52
- }
53
- if (this.config.debug) {
54
- this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);
55
- }
56
- for (const pattern of this.config.messages) {
57
- if (this.config.debug) {
58
- this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);
59
- }
60
- const matches = typeof pattern === "string" ? this.context.message.includes(pattern) : pattern.test(this.context.message);
61
- if (matches) {
62
- this.context.debugItems.push("[filter-plugin] pattern match: true");
63
- return true;
64
- }
65
- this.context.debugItems.push("[filter-plugin] pattern match: false");
66
- }
67
- return false;
68
- }
69
- /**
70
- * Checks if the current message matches any of the configured queries.
71
- * Uses @jsonquerylang/jsonquery for query execution.
72
- *
73
- * @returns true if any query matches, false otherwise
74
- */
75
- checkQueries() {
76
- if (!_optionalChain([this, 'access', _7 => _7.config, 'access', _8 => _8.queries, 'optionalAccess', _9 => _9.length])) {
77
- return false;
78
- }
79
- const queryContext = {
80
- level: this.context.logLevel,
81
- message: this.context.message,
82
- data: this.context.data
83
- };
84
- try {
85
- for (const q of this.config.queries) {
86
- const conditions = q.split(" or ").map((cond) => `filter(${cond.trim().replaceAll(`'`, `"`)})`);
87
- const query = conditions.join(" or ");
88
- if (this.config.debug) {
89
- this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);
90
- this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
91
- }
92
- for (const condition of conditions) {
93
- try {
94
- const output = _jsonquery.jsonquery.call(void 0, [queryContext], condition);
95
- if (output.length > 0) {
96
- if (this.config.debug) {
97
- this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);
98
- }
99
- return true;
100
- }
101
- } catch (e) {
102
- console.error(`[filter-plugin] Error: ${e}`);
103
- console.log(`[filter-plugin] query: ${condition}`);
104
- console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
105
- }
106
- }
107
- if (this.config.debug) {
108
- this.context.debugItems.push("[filter-plugin] query match: false");
109
- }
110
- }
111
- return false;
112
- } catch (e) {
113
- console.error(`[filter-plugin] Error: ${e}`);
114
- console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);
115
- console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
116
- return false;
117
- }
118
- }
119
- /**
120
- * Checks if a log message should be allowed based on the configured filters.
121
- *
122
- * The filtering logic is:
123
- * 1. If no filters defined, allow all logs
124
- * 2. If message patterns match, allow the log
125
- * 3. If queries match, allow the log
126
- * 4. Otherwise, filter out the log
127
- *
128
- * @param params - The log message parameters
129
- * @returns true if the log should be allowed, false otherwise
130
- */
131
- check(params) {
132
- this.resetContext(params);
133
- if (!_optionalChain([this, 'access', _10 => _10.config, 'access', _11 => _11.messages, 'optionalAccess', _12 => _12.length]) && !_optionalChain([this, 'access', _13 => _13.config, 'access', _14 => _14.queries, 'optionalAccess', _15 => _15.length])) {
134
- this.context.debugItems.push("[filter-plugin] no filters defined, allowing message");
135
- this.printDebugItems();
136
- return true;
137
- }
138
- if (this.checkMessagePatterns()) {
139
- this.printDebugItems();
140
- return true;
141
- }
142
- const queryResult = this.checkQueries();
143
- this.printDebugItems();
144
- return queryResult;
145
- }
35
+ config;
36
+ context;
37
+ /**
38
+ * Creates a new FilterExecutor instance.
39
+ *
40
+ * @param config - The filter plugin configuration
41
+ */
42
+ constructor(config) {
43
+ this.config = config;
44
+ this.context = {
45
+ message: "",
46
+ logLevel: "",
47
+ data: {},
48
+ debugItems: []
49
+ };
50
+ }
51
+ /**
52
+ * Resets the context for a new log message check.
53
+ *
54
+ * @param params - The log message parameters
55
+ */
56
+ resetContext(params) {
57
+ this.context = {
58
+ message: params.messages?.join(" ") || "",
59
+ logLevel: params.logLevel,
60
+ data: params.data || {},
61
+ debugItems: ["[filter-plugin] ================================="]
62
+ };
63
+ }
64
+ /**
65
+ * Prints debug information if debug mode is enabled.
66
+ */
67
+ printDebugItems() {
68
+ if (this.config.debug) for (const item of this.context.debugItems) console.log(item);
69
+ }
70
+ /**
71
+ * Checks if the current message matches any of the configured patterns.
72
+ * Supports both string and RegExp patterns.
73
+ *
74
+ * @returns true if any pattern matches, false otherwise
75
+ */
76
+ checkMessagePatterns() {
77
+ if (!this.config.messages?.length) return false;
78
+ if (this.config.debug) this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);
79
+ for (const pattern of this.config.messages) {
80
+ if (this.config.debug) this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);
81
+ if (typeof pattern === "string" ? this.context.message.includes(pattern) : pattern.test(this.context.message)) {
82
+ this.context.debugItems.push("[filter-plugin] pattern match: true");
83
+ return true;
84
+ }
85
+ this.context.debugItems.push("[filter-plugin] pattern match: false");
86
+ }
87
+ return false;
88
+ }
89
+ /**
90
+ * Checks if the current message matches any of the configured queries.
91
+ * Uses @jsonquerylang/jsonquery for query execution.
92
+ *
93
+ * @returns true if any query matches, false otherwise
94
+ */
95
+ checkQueries() {
96
+ if (!this.config.queries?.length) return false;
97
+ const queryContext = {
98
+ level: this.context.logLevel,
99
+ message: this.context.message,
100
+ data: this.context.data
101
+ };
102
+ try {
103
+ for (const q of this.config.queries) {
104
+ const conditions = q.split(" or ").map((cond) => `filter(${cond.trim().replaceAll(`'`, `"`)})`);
105
+ const query = conditions.join(" or ");
106
+ if (this.config.debug) {
107
+ this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);
108
+ this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
109
+ }
110
+ for (const condition of conditions) try {
111
+ const output = (0, __jsonquerylang_jsonquery.jsonquery)([queryContext], condition);
112
+ if (output.length > 0) {
113
+ if (this.config.debug) this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);
114
+ return true;
115
+ }
116
+ } catch (e) {
117
+ console.error(`[filter-plugin] Error: ${e}`);
118
+ console.log(`[filter-plugin] query: ${condition}`);
119
+ console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
120
+ }
121
+ if (this.config.debug) this.context.debugItems.push("[filter-plugin] query match: false");
122
+ }
123
+ return false;
124
+ } catch (e) {
125
+ console.error(`[filter-plugin] Error: ${e}`);
126
+ console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);
127
+ console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
128
+ return false;
129
+ }
130
+ }
131
+ /**
132
+ * Checks if a log message should be allowed based on the configured filters.
133
+ *
134
+ * The filtering logic is:
135
+ * 1. If no filters defined, allow all logs
136
+ * 2. If message patterns match, allow the log
137
+ * 3. If queries match, allow the log
138
+ * 4. Otherwise, filter out the log
139
+ *
140
+ * @param params - The log message parameters
141
+ * @returns true if the log should be allowed, false otherwise
142
+ */
143
+ check(params) {
144
+ this.resetContext(params);
145
+ if (!this.config.messages?.length && !this.config.queries?.length) {
146
+ this.context.debugItems.push("[filter-plugin] no filters defined, allowing message");
147
+ this.printDebugItems();
148
+ return true;
149
+ }
150
+ if (this.checkMessagePatterns()) {
151
+ this.printDebugItems();
152
+ return true;
153
+ }
154
+ const queryResult = this.checkQueries();
155
+ this.printDebugItems();
156
+ return queryResult;
157
+ }
146
158
  };
147
159
 
148
- // src/plugin.ts
160
+ //#endregion
161
+ //#region src/plugin.ts
162
+ /**
163
+ * Creates a new filter plugin instance.
164
+ *
165
+ * The filter plugin allows filtering log messages based on:
166
+ * - String patterns
167
+ * - Regular expressions
168
+ * - JSON queries
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * // Filter error messages
173
+ * const filter = filterPlugin({
174
+ * messages: ['error'],
175
+ * });
176
+ *
177
+ * // Filter by log level
178
+ * const levelFilter = filterPlugin({
179
+ * queries: ['.level == "error" or .level == "warn"'],
180
+ * });
181
+ * ```
182
+ *
183
+ * @param config - The filter plugin configuration
184
+ * @returns A LogLayer plugin instance
185
+ */
149
186
  function filterPlugin(config) {
150
- const executor = new FilterExecutor(config);
151
- return {
152
- id: config.id,
153
- disabled: config.disabled,
154
- shouldSendToLogger: (params) => {
155
- return executor.check(params);
156
- }
157
- };
187
+ const executor = new FilterExecutor(config);
188
+ return {
189
+ id: config.id,
190
+ disabled: config.disabled,
191
+ shouldSendToLogger: (params) => {
192
+ return executor.check(params);
193
+ }
194
+ };
158
195
  }
159
196
 
160
-
197
+ //#endregion
161
198
  exports.filterPlugin = filterPlugin;
162
199
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/loglayer/loglayer/packages/plugins/filter/dist/index.cjs","../src/FilterExecutor.ts","../src/plugin.ts"],"names":[],"mappings":"AAAA;ACAA,qDAA0B;AAyBnB,IAAM,eAAA,EAAN,MAAqB;AAAA,EACT;AAAA,EAC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/packages/plugins/filter/dist/index.cjs","sourcesContent":[null,"import { jsonquery } from \"@jsonquerylang/jsonquery\";\nimport type { PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Internal context for the filter execution.\n * Contains the current log message details and debug information.\n */\ninterface FilterContext {\n /** The combined log message */\n message: string;\n /** The log level */\n logLevel: string;\n /** Additional log data */\n data: Record<string, any>;\n /** Debug messages for troubleshooting */\n debugItems: string[];\n}\n\n/**\n * Core filtering logic implementation.\n * Handles pattern matching and query-based filtering of log messages.\n *\n * @internal\n */\nexport class FilterExecutor {\n private readonly config: filterPluginParams;\n private context: FilterContext;\n\n /**\n * Creates a new FilterExecutor instance.\n *\n * @param config - The filter plugin configuration\n */\n constructor(config: filterPluginParams) {\n this.config = config;\n this.context = {\n message: \"\",\n logLevel: \"\",\n data: {},\n debugItems: [],\n };\n }\n\n /**\n * Resets the context for a new log message check.\n *\n * @param params - The log message parameters\n */\n private resetContext(params: PluginShouldSendToLoggerParams): void {\n this.context = {\n message: params.messages?.join(\" \") || \"\",\n logLevel: params.logLevel,\n data: params.data || {},\n debugItems: [\"[filter-plugin] =================================\"],\n };\n }\n\n /**\n * Prints debug information if debug mode is enabled.\n */\n private printDebugItems(): void {\n if (this.config.debug) {\n for (const item of this.context.debugItems) {\n console.log(item);\n }\n }\n }\n\n /**\n * Checks if the current message matches any of the configured patterns.\n * Supports both string and RegExp patterns.\n *\n * @returns true if any pattern matches, false otherwise\n */\n private checkMessagePatterns(): boolean {\n if (!this.config.messages?.length) {\n return false;\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);\n }\n\n for (const pattern of this.config.messages) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);\n }\n\n const matches =\n typeof pattern === \"string\" ? this.context.message.includes(pattern) : pattern.test(this.context.message);\n\n if (matches) {\n this.context.debugItems.push(\"[filter-plugin] pattern match: true\");\n return true;\n }\n\n this.context.debugItems.push(\"[filter-plugin] pattern match: false\");\n }\n\n return false;\n }\n\n /**\n * Checks if the current message matches any of the configured queries.\n * Uses @jsonquerylang/jsonquery for query execution.\n *\n * @returns true if any query matches, false otherwise\n */\n private checkQueries(): boolean {\n if (!this.config.queries?.length) {\n return false;\n }\n\n const queryContext = {\n level: this.context.logLevel,\n message: this.context.message,\n data: this.context.data,\n };\n\n try {\n // Process each query individually and return true if any match\n for (const q of this.config.queries) {\n // Split OR conditions and wrap each in filter()\n const conditions = q.split(\" or \").map((cond) => `filter(${cond.trim().replaceAll(`'`, `\"`)})`);\n const query = conditions.join(\" or \");\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);\n this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n }\n\n // Try each condition separately\n for (const condition of conditions) {\n try {\n const output = jsonquery([queryContext], condition) as Array<any>;\n if (output.length > 0) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);\n }\n return true;\n }\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] query: ${condition}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n // Continue trying other conditions\n }\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(\"[filter-plugin] query match: false\");\n }\n }\n\n return false;\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n return false;\n }\n }\n\n /**\n * Checks if a log message should be allowed based on the configured filters.\n *\n * The filtering logic is:\n * 1. If no filters defined, allow all logs\n * 2. If message patterns match, allow the log\n * 3. If queries match, allow the log\n * 4. Otherwise, filter out the log\n *\n * @param params - The log message parameters\n * @returns true if the log should be allowed, false otherwise\n */\n check(params: PluginShouldSendToLoggerParams): boolean {\n this.resetContext(params);\n\n // If no filters defined at all, allow everything\n if (!this.config.messages?.length && !this.config.queries?.length) {\n this.context.debugItems.push(\"[filter-plugin] no filters defined, allowing message\");\n this.printDebugItems();\n return true;\n }\n\n // Check message patterns first\n if (this.checkMessagePatterns()) {\n this.printDebugItems();\n return true;\n }\n\n // Then check queries if message patterns didn't match\n const queryResult = this.checkQueries();\n this.printDebugItems();\n return queryResult;\n }\n}\n","import type { LogLayerPlugin, PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport { FilterExecutor } from \"./FilterExecutor.js\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Creates a new filter plugin instance.\n *\n * The filter plugin allows filtering log messages based on:\n * - String patterns\n * - Regular expressions\n * - JSON queries\n *\n * @example\n * ```typescript\n * // Filter error messages\n * const filter = filterPlugin({\n * messages: ['error'],\n * });\n *\n * // Filter by log level\n * const levelFilter = filterPlugin({\n * queries: ['.level == \"error\" or .level == \"warn\"'],\n * });\n * ```\n *\n * @param config - The filter plugin configuration\n * @returns A LogLayer plugin instance\n */\nexport function filterPlugin(config: filterPluginParams): LogLayerPlugin {\n const executor = new FilterExecutor(config);\n\n return {\n id: config.id,\n disabled: config.disabled,\n shouldSendToLogger: (params: PluginShouldSendToLoggerParams) => {\n return executor.check(params);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/FilterExecutor.ts","../src/plugin.ts"],"sourcesContent":["import { jsonquery } from \"@jsonquerylang/jsonquery\";\nimport type { PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Internal context for the filter execution.\n * Contains the current log message details and debug information.\n */\ninterface FilterContext {\n /** The combined log message */\n message: string;\n /** The log level */\n logLevel: string;\n /** Additional log data */\n data: Record<string, any>;\n /** Debug messages for troubleshooting */\n debugItems: string[];\n}\n\n/**\n * Core filtering logic implementation.\n * Handles pattern matching and query-based filtering of log messages.\n *\n * @internal\n */\nexport class FilterExecutor {\n private readonly config: filterPluginParams;\n private context: FilterContext;\n\n /**\n * Creates a new FilterExecutor instance.\n *\n * @param config - The filter plugin configuration\n */\n constructor(config: filterPluginParams) {\n this.config = config;\n this.context = {\n message: \"\",\n logLevel: \"\",\n data: {},\n debugItems: [],\n };\n }\n\n /**\n * Resets the context for a new log message check.\n *\n * @param params - The log message parameters\n */\n private resetContext(params: PluginShouldSendToLoggerParams): void {\n this.context = {\n message: params.messages?.join(\" \") || \"\",\n logLevel: params.logLevel,\n data: params.data || {},\n debugItems: [\"[filter-plugin] =================================\"],\n };\n }\n\n /**\n * Prints debug information if debug mode is enabled.\n */\n private printDebugItems(): void {\n if (this.config.debug) {\n for (const item of this.context.debugItems) {\n console.log(item);\n }\n }\n }\n\n /**\n * Checks if the current message matches any of the configured patterns.\n * Supports both string and RegExp patterns.\n *\n * @returns true if any pattern matches, false otherwise\n */\n private checkMessagePatterns(): boolean {\n if (!this.config.messages?.length) {\n return false;\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);\n }\n\n for (const pattern of this.config.messages) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);\n }\n\n const matches =\n typeof pattern === \"string\" ? this.context.message.includes(pattern) : pattern.test(this.context.message);\n\n if (matches) {\n this.context.debugItems.push(\"[filter-plugin] pattern match: true\");\n return true;\n }\n\n this.context.debugItems.push(\"[filter-plugin] pattern match: false\");\n }\n\n return false;\n }\n\n /**\n * Checks if the current message matches any of the configured queries.\n * Uses @jsonquerylang/jsonquery for query execution.\n *\n * @returns true if any query matches, false otherwise\n */\n private checkQueries(): boolean {\n if (!this.config.queries?.length) {\n return false;\n }\n\n const queryContext = {\n level: this.context.logLevel,\n message: this.context.message,\n data: this.context.data,\n };\n\n try {\n // Process each query individually and return true if any match\n for (const q of this.config.queries) {\n // Split OR conditions and wrap each in filter()\n const conditions = q.split(\" or \").map((cond) => `filter(${cond.trim().replaceAll(`'`, `\"`)})`);\n const query = conditions.join(\" or \");\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);\n this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n }\n\n // Try each condition separately\n for (const condition of conditions) {\n try {\n const output = jsonquery([queryContext], condition) as Array<any>;\n if (output.length > 0) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);\n }\n return true;\n }\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] query: ${condition}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n // Continue trying other conditions\n }\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(\"[filter-plugin] query match: false\");\n }\n }\n\n return false;\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n return false;\n }\n }\n\n /**\n * Checks if a log message should be allowed based on the configured filters.\n *\n * The filtering logic is:\n * 1. If no filters defined, allow all logs\n * 2. If message patterns match, allow the log\n * 3. If queries match, allow the log\n * 4. Otherwise, filter out the log\n *\n * @param params - The log message parameters\n * @returns true if the log should be allowed, false otherwise\n */\n check(params: PluginShouldSendToLoggerParams): boolean {\n this.resetContext(params);\n\n // If no filters defined at all, allow everything\n if (!this.config.messages?.length && !this.config.queries?.length) {\n this.context.debugItems.push(\"[filter-plugin] no filters defined, allowing message\");\n this.printDebugItems();\n return true;\n }\n\n // Check message patterns first\n if (this.checkMessagePatterns()) {\n this.printDebugItems();\n return true;\n }\n\n // Then check queries if message patterns didn't match\n const queryResult = this.checkQueries();\n this.printDebugItems();\n return queryResult;\n }\n}\n","import type { LogLayerPlugin, PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport { FilterExecutor } from \"./FilterExecutor.js\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Creates a new filter plugin instance.\n *\n * The filter plugin allows filtering log messages based on:\n * - String patterns\n * - Regular expressions\n * - JSON queries\n *\n * @example\n * ```typescript\n * // Filter error messages\n * const filter = filterPlugin({\n * messages: ['error'],\n * });\n *\n * // Filter by log level\n * const levelFilter = filterPlugin({\n * queries: ['.level == \"error\" or .level == \"warn\"'],\n * });\n * ```\n *\n * @param config - The filter plugin configuration\n * @returns A LogLayer plugin instance\n */\nexport function filterPlugin(config: filterPluginParams): LogLayerPlugin {\n const executor = new FilterExecutor(config);\n\n return {\n id: config.id,\n disabled: config.disabled,\n shouldSendToLogger: (params: PluginShouldSendToLoggerParams) => {\n return executor.check(params);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,iBAAb,MAA4B;CAC1B,AAAiB;CACjB,AAAQ;;;;;;CAOR,YAAY,QAA4B;AACtC,OAAK,SAAS;AACd,OAAK,UAAU;GACb,SAAS;GACT,UAAU;GACV,MAAM,EAAE;GACR,YAAY,EAAE;GACf;;;;;;;CAQH,AAAQ,aAAa,QAA8C;AACjE,OAAK,UAAU;GACb,SAAS,OAAO,UAAU,KAAK,IAAI,IAAI;GACvC,UAAU,OAAO;GACjB,MAAM,OAAO,QAAQ,EAAE;GACvB,YAAY,CAAC,oDAAoD;GAClE;;;;;CAMH,AAAQ,kBAAwB;AAC9B,MAAI,KAAK,OAAO,MACd,MAAK,MAAM,QAAQ,KAAK,QAAQ,WAC9B,SAAQ,IAAI,KAAK;;;;;;;;CAWvB,AAAQ,uBAAgC;AACtC,MAAI,CAAC,KAAK,OAAO,UAAU,OACzB,QAAO;AAGT,MAAI,KAAK,OAAO,MACd,MAAK,QAAQ,WAAW,KAAK,4BAA4B,KAAK,QAAQ,UAAU;AAGlF,OAAK,MAAM,WAAW,KAAK,OAAO,UAAU;AAC1C,OAAI,KAAK,OAAO,MACd,MAAK,QAAQ,WAAW,KAAK,4BAA4B,UAAU;AAMrE,OAFE,OAAO,YAAY,WAAW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AAG;AAC9E,WAAQ,IAAI,0BAA0B,KAAK,UAAU,aAAa,GAAG;AACrE,UAAO;;;;;;;;;;;;;;;CAgBX,MAAM,QAAiD;AACrD,OAAK,aAAa,OAAO;AAGzB,MAAI,CAAC,KAAK,OAAO,UAAU,UAAU,CAAC,KAAK,OAAO,SAAS,QAAQ;AACjE,QAAK,QAAQ,WAAW,KAAK,uDAAuD;AACpF,QAAK,iBAAiB;AACtB,UAAO;;AAIT,MAAI,KAAK,sBAAsB,EAAE;AAC/B,QAAK,iBAAiB;AACtB,UAAO;;EAIT,MAAM,cAAc,KAAK,cAAc;AACvC,OAAK,iBAAiB;AACtB,SAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACvKX,SAAgB,aAAa,QAA4C;CACvE,MAAM,WAAW,IAAI,eAAe,OAAO;AAE3C,QAAO;EACL,IAAI,OAAO;EACX,UAAU,OAAO;EACjB,qBAAqB,WAA2C;AAC9D,UAAO,SAAS,MAAM,OAAO;;EAEhC"}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
- import { LogLayerPluginParams, LogLayerPlugin } from '@loglayer/plugin';
1
+ import { LogLayerPlugin, LogLayerPluginParams } from "@loglayer/plugin";
2
+
3
+ //#region src/types.d.ts
2
4
 
3
5
  /**
4
6
  * Configuration parameters for the filter plugin.
@@ -14,40 +16,41 @@ import { LogLayerPluginParams, LogLayerPlugin } from '@loglayer/plugin';
14
16
  * ```
15
17
  */
16
18
  interface filterPluginParams extends LogLayerPluginParams {
17
- /**
18
- * Array of string patterns or regular expressions to match against log messages.
19
- * If any pattern matches, the log will be allowed.
20
- *
21
- * @example
22
- * ```typescript
23
- * messages: ['error', /warning\d+/]
24
- * ```
25
- */
26
- messages?: Array<string | RegExp>;
27
- /**
28
- * Array of JSON queries to filter logs.
29
- * If any query matches, the log will be allowed.
30
- * Uses @jsonquerylang/jsonquery syntax.
31
- *
32
- * @example
33
- * ```typescript
34
- * queries: ['.level == "error"', '.data.userId == "123"']
35
- * ```
36
- */
37
- queries?: Array<string>;
38
- /**
39
- * Enable debug mode to see detailed information about the filtering process.
40
- * When enabled, the plugin will log:
41
- * - Message content
42
- * - Pattern matching results
43
- * - Query execution details
44
- * - Final filtering decision
45
- *
46
- * @default false
47
- */
48
- debug?: boolean;
19
+ /**
20
+ * Array of string patterns or regular expressions to match against log messages.
21
+ * If any pattern matches, the log will be allowed.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * messages: ['error', /warning\d+/]
26
+ * ```
27
+ */
28
+ messages?: Array<string | RegExp>;
29
+ /**
30
+ * Array of JSON queries to filter logs.
31
+ * If any query matches, the log will be allowed.
32
+ * Uses @jsonquerylang/jsonquery syntax.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * queries: ['.level == "error"', '.data.userId == "123"']
37
+ * ```
38
+ */
39
+ queries?: Array<string>;
40
+ /**
41
+ * Enable debug mode to see detailed information about the filtering process.
42
+ * When enabled, the plugin will log:
43
+ * - Message content
44
+ * - Pattern matching results
45
+ * - Query execution details
46
+ * - Final filtering decision
47
+ *
48
+ * @default false
49
+ */
50
+ debug?: boolean;
49
51
  }
50
-
52
+ //#endregion
53
+ //#region src/plugin.d.ts
51
54
  /**
52
55
  * Creates a new filter plugin instance.
53
56
  *
@@ -73,5 +76,6 @@ interface filterPluginParams extends LogLayerPluginParams {
73
76
  * @returns A LogLayer plugin instance
74
77
  */
75
78
  declare function filterPlugin(config: filterPluginParams): LogLayerPlugin;
76
-
79
+ //#endregion
77
80
  export { filterPlugin, type filterPluginParams };
81
+ //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { LogLayerPluginParams, LogLayerPlugin } from '@loglayer/plugin';
1
+ import { LogLayerPlugin, LogLayerPluginParams } from "@loglayer/plugin";
2
+
3
+ //#region src/types.d.ts
2
4
 
3
5
  /**
4
6
  * Configuration parameters for the filter plugin.
@@ -14,40 +16,41 @@ import { LogLayerPluginParams, LogLayerPlugin } from '@loglayer/plugin';
14
16
  * ```
15
17
  */
16
18
  interface filterPluginParams extends LogLayerPluginParams {
17
- /**
18
- * Array of string patterns or regular expressions to match against log messages.
19
- * If any pattern matches, the log will be allowed.
20
- *
21
- * @example
22
- * ```typescript
23
- * messages: ['error', /warning\d+/]
24
- * ```
25
- */
26
- messages?: Array<string | RegExp>;
27
- /**
28
- * Array of JSON queries to filter logs.
29
- * If any query matches, the log will be allowed.
30
- * Uses @jsonquerylang/jsonquery syntax.
31
- *
32
- * @example
33
- * ```typescript
34
- * queries: ['.level == "error"', '.data.userId == "123"']
35
- * ```
36
- */
37
- queries?: Array<string>;
38
- /**
39
- * Enable debug mode to see detailed information about the filtering process.
40
- * When enabled, the plugin will log:
41
- * - Message content
42
- * - Pattern matching results
43
- * - Query execution details
44
- * - Final filtering decision
45
- *
46
- * @default false
47
- */
48
- debug?: boolean;
19
+ /**
20
+ * Array of string patterns or regular expressions to match against log messages.
21
+ * If any pattern matches, the log will be allowed.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * messages: ['error', /warning\d+/]
26
+ * ```
27
+ */
28
+ messages?: Array<string | RegExp>;
29
+ /**
30
+ * Array of JSON queries to filter logs.
31
+ * If any query matches, the log will be allowed.
32
+ * Uses @jsonquerylang/jsonquery syntax.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * queries: ['.level == "error"', '.data.userId == "123"']
37
+ * ```
38
+ */
39
+ queries?: Array<string>;
40
+ /**
41
+ * Enable debug mode to see detailed information about the filtering process.
42
+ * When enabled, the plugin will log:
43
+ * - Message content
44
+ * - Pattern matching results
45
+ * - Query execution details
46
+ * - Final filtering decision
47
+ *
48
+ * @default false
49
+ */
50
+ debug?: boolean;
49
51
  }
50
-
52
+ //#endregion
53
+ //#region src/plugin.d.ts
51
54
  /**
52
55
  * Creates a new filter plugin instance.
53
56
  *
@@ -73,5 +76,6 @@ interface filterPluginParams extends LogLayerPluginParams {
73
76
  * @returns A LogLayer plugin instance
74
77
  */
75
78
  declare function filterPlugin(config: filterPluginParams): LogLayerPlugin;
76
-
79
+ //#endregion
77
80
  export { filterPlugin, type filterPluginParams };
81
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,162 +1,175 @@
1
- // src/FilterExecutor.ts
2
1
  import { jsonquery } from "@jsonquerylang/jsonquery";
2
+
3
+ //#region src/FilterExecutor.ts
4
+ /**
5
+ * Core filtering logic implementation.
6
+ * Handles pattern matching and query-based filtering of log messages.
7
+ *
8
+ * @internal
9
+ */
3
10
  var FilterExecutor = class {
4
- config;
5
- context;
6
- /**
7
- * Creates a new FilterExecutor instance.
8
- *
9
- * @param config - The filter plugin configuration
10
- */
11
- constructor(config) {
12
- this.config = config;
13
- this.context = {
14
- message: "",
15
- logLevel: "",
16
- data: {},
17
- debugItems: []
18
- };
19
- }
20
- /**
21
- * Resets the context for a new log message check.
22
- *
23
- * @param params - The log message parameters
24
- */
25
- resetContext(params) {
26
- this.context = {
27
- message: params.messages?.join(" ") || "",
28
- logLevel: params.logLevel,
29
- data: params.data || {},
30
- debugItems: ["[filter-plugin] ================================="]
31
- };
32
- }
33
- /**
34
- * Prints debug information if debug mode is enabled.
35
- */
36
- printDebugItems() {
37
- if (this.config.debug) {
38
- for (const item of this.context.debugItems) {
39
- console.log(item);
40
- }
41
- }
42
- }
43
- /**
44
- * Checks if the current message matches any of the configured patterns.
45
- * Supports both string and RegExp patterns.
46
- *
47
- * @returns true if any pattern matches, false otherwise
48
- */
49
- checkMessagePatterns() {
50
- if (!this.config.messages?.length) {
51
- return false;
52
- }
53
- if (this.config.debug) {
54
- this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);
55
- }
56
- for (const pattern of this.config.messages) {
57
- if (this.config.debug) {
58
- this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);
59
- }
60
- const matches = typeof pattern === "string" ? this.context.message.includes(pattern) : pattern.test(this.context.message);
61
- if (matches) {
62
- this.context.debugItems.push("[filter-plugin] pattern match: true");
63
- return true;
64
- }
65
- this.context.debugItems.push("[filter-plugin] pattern match: false");
66
- }
67
- return false;
68
- }
69
- /**
70
- * Checks if the current message matches any of the configured queries.
71
- * Uses @jsonquerylang/jsonquery for query execution.
72
- *
73
- * @returns true if any query matches, false otherwise
74
- */
75
- checkQueries() {
76
- if (!this.config.queries?.length) {
77
- return false;
78
- }
79
- const queryContext = {
80
- level: this.context.logLevel,
81
- message: this.context.message,
82
- data: this.context.data
83
- };
84
- try {
85
- for (const q of this.config.queries) {
86
- const conditions = q.split(" or ").map((cond) => `filter(${cond.trim().replaceAll(`'`, `"`)})`);
87
- const query = conditions.join(" or ");
88
- if (this.config.debug) {
89
- this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);
90
- this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
91
- }
92
- for (const condition of conditions) {
93
- try {
94
- const output = jsonquery([queryContext], condition);
95
- if (output.length > 0) {
96
- if (this.config.debug) {
97
- this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);
98
- }
99
- return true;
100
- }
101
- } catch (e) {
102
- console.error(`[filter-plugin] Error: ${e}`);
103
- console.log(`[filter-plugin] query: ${condition}`);
104
- console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
105
- }
106
- }
107
- if (this.config.debug) {
108
- this.context.debugItems.push("[filter-plugin] query match: false");
109
- }
110
- }
111
- return false;
112
- } catch (e) {
113
- console.error(`[filter-plugin] Error: ${e}`);
114
- console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);
115
- console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
116
- return false;
117
- }
118
- }
119
- /**
120
- * Checks if a log message should be allowed based on the configured filters.
121
- *
122
- * The filtering logic is:
123
- * 1. If no filters defined, allow all logs
124
- * 2. If message patterns match, allow the log
125
- * 3. If queries match, allow the log
126
- * 4. Otherwise, filter out the log
127
- *
128
- * @param params - The log message parameters
129
- * @returns true if the log should be allowed, false otherwise
130
- */
131
- check(params) {
132
- this.resetContext(params);
133
- if (!this.config.messages?.length && !this.config.queries?.length) {
134
- this.context.debugItems.push("[filter-plugin] no filters defined, allowing message");
135
- this.printDebugItems();
136
- return true;
137
- }
138
- if (this.checkMessagePatterns()) {
139
- this.printDebugItems();
140
- return true;
141
- }
142
- const queryResult = this.checkQueries();
143
- this.printDebugItems();
144
- return queryResult;
145
- }
11
+ config;
12
+ context;
13
+ /**
14
+ * Creates a new FilterExecutor instance.
15
+ *
16
+ * @param config - The filter plugin configuration
17
+ */
18
+ constructor(config) {
19
+ this.config = config;
20
+ this.context = {
21
+ message: "",
22
+ logLevel: "",
23
+ data: {},
24
+ debugItems: []
25
+ };
26
+ }
27
+ /**
28
+ * Resets the context for a new log message check.
29
+ *
30
+ * @param params - The log message parameters
31
+ */
32
+ resetContext(params) {
33
+ this.context = {
34
+ message: params.messages?.join(" ") || "",
35
+ logLevel: params.logLevel,
36
+ data: params.data || {},
37
+ debugItems: ["[filter-plugin] ================================="]
38
+ };
39
+ }
40
+ /**
41
+ * Prints debug information if debug mode is enabled.
42
+ */
43
+ printDebugItems() {
44
+ if (this.config.debug) for (const item of this.context.debugItems) console.log(item);
45
+ }
46
+ /**
47
+ * Checks if the current message matches any of the configured patterns.
48
+ * Supports both string and RegExp patterns.
49
+ *
50
+ * @returns true if any pattern matches, false otherwise
51
+ */
52
+ checkMessagePatterns() {
53
+ if (!this.config.messages?.length) return false;
54
+ if (this.config.debug) this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);
55
+ for (const pattern of this.config.messages) {
56
+ if (this.config.debug) this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);
57
+ if (typeof pattern === "string" ? this.context.message.includes(pattern) : pattern.test(this.context.message)) {
58
+ this.context.debugItems.push("[filter-plugin] pattern match: true");
59
+ return true;
60
+ }
61
+ this.context.debugItems.push("[filter-plugin] pattern match: false");
62
+ }
63
+ return false;
64
+ }
65
+ /**
66
+ * Checks if the current message matches any of the configured queries.
67
+ * Uses @jsonquerylang/jsonquery for query execution.
68
+ *
69
+ * @returns true if any query matches, false otherwise
70
+ */
71
+ checkQueries() {
72
+ if (!this.config.queries?.length) return false;
73
+ const queryContext = {
74
+ level: this.context.logLevel,
75
+ message: this.context.message,
76
+ data: this.context.data
77
+ };
78
+ try {
79
+ for (const q of this.config.queries) {
80
+ const conditions = q.split(" or ").map((cond) => `filter(${cond.trim().replaceAll(`'`, `"`)})`);
81
+ const query = conditions.join(" or ");
82
+ if (this.config.debug) {
83
+ this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);
84
+ this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
85
+ }
86
+ for (const condition of conditions) try {
87
+ const output = jsonquery([queryContext], condition);
88
+ if (output.length > 0) {
89
+ if (this.config.debug) this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);
90
+ return true;
91
+ }
92
+ } catch (e) {
93
+ console.error(`[filter-plugin] Error: ${e}`);
94
+ console.log(`[filter-plugin] query: ${condition}`);
95
+ console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
96
+ }
97
+ if (this.config.debug) this.context.debugItems.push("[filter-plugin] query match: false");
98
+ }
99
+ return false;
100
+ } catch (e) {
101
+ console.error(`[filter-plugin] Error: ${e}`);
102
+ console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);
103
+ console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);
104
+ return false;
105
+ }
106
+ }
107
+ /**
108
+ * Checks if a log message should be allowed based on the configured filters.
109
+ *
110
+ * The filtering logic is:
111
+ * 1. If no filters defined, allow all logs
112
+ * 2. If message patterns match, allow the log
113
+ * 3. If queries match, allow the log
114
+ * 4. Otherwise, filter out the log
115
+ *
116
+ * @param params - The log message parameters
117
+ * @returns true if the log should be allowed, false otherwise
118
+ */
119
+ check(params) {
120
+ this.resetContext(params);
121
+ if (!this.config.messages?.length && !this.config.queries?.length) {
122
+ this.context.debugItems.push("[filter-plugin] no filters defined, allowing message");
123
+ this.printDebugItems();
124
+ return true;
125
+ }
126
+ if (this.checkMessagePatterns()) {
127
+ this.printDebugItems();
128
+ return true;
129
+ }
130
+ const queryResult = this.checkQueries();
131
+ this.printDebugItems();
132
+ return queryResult;
133
+ }
146
134
  };
147
135
 
148
- // src/plugin.ts
136
+ //#endregion
137
+ //#region src/plugin.ts
138
+ /**
139
+ * Creates a new filter plugin instance.
140
+ *
141
+ * The filter plugin allows filtering log messages based on:
142
+ * - String patterns
143
+ * - Regular expressions
144
+ * - JSON queries
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Filter error messages
149
+ * const filter = filterPlugin({
150
+ * messages: ['error'],
151
+ * });
152
+ *
153
+ * // Filter by log level
154
+ * const levelFilter = filterPlugin({
155
+ * queries: ['.level == "error" or .level == "warn"'],
156
+ * });
157
+ * ```
158
+ *
159
+ * @param config - The filter plugin configuration
160
+ * @returns A LogLayer plugin instance
161
+ */
149
162
  function filterPlugin(config) {
150
- const executor = new FilterExecutor(config);
151
- return {
152
- id: config.id,
153
- disabled: config.disabled,
154
- shouldSendToLogger: (params) => {
155
- return executor.check(params);
156
- }
157
- };
163
+ const executor = new FilterExecutor(config);
164
+ return {
165
+ id: config.id,
166
+ disabled: config.disabled,
167
+ shouldSendToLogger: (params) => {
168
+ return executor.check(params);
169
+ }
170
+ };
158
171
  }
159
- export {
160
- filterPlugin
161
- };
172
+
173
+ //#endregion
174
+ export { filterPlugin };
162
175
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/FilterExecutor.ts","../src/plugin.ts"],"sourcesContent":["import { jsonquery } from \"@jsonquerylang/jsonquery\";\nimport type { PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Internal context for the filter execution.\n * Contains the current log message details and debug information.\n */\ninterface FilterContext {\n /** The combined log message */\n message: string;\n /** The log level */\n logLevel: string;\n /** Additional log data */\n data: Record<string, any>;\n /** Debug messages for troubleshooting */\n debugItems: string[];\n}\n\n/**\n * Core filtering logic implementation.\n * Handles pattern matching and query-based filtering of log messages.\n *\n * @internal\n */\nexport class FilterExecutor {\n private readonly config: filterPluginParams;\n private context: FilterContext;\n\n /**\n * Creates a new FilterExecutor instance.\n *\n * @param config - The filter plugin configuration\n */\n constructor(config: filterPluginParams) {\n this.config = config;\n this.context = {\n message: \"\",\n logLevel: \"\",\n data: {},\n debugItems: [],\n };\n }\n\n /**\n * Resets the context for a new log message check.\n *\n * @param params - The log message parameters\n */\n private resetContext(params: PluginShouldSendToLoggerParams): void {\n this.context = {\n message: params.messages?.join(\" \") || \"\",\n logLevel: params.logLevel,\n data: params.data || {},\n debugItems: [\"[filter-plugin] =================================\"],\n };\n }\n\n /**\n * Prints debug information if debug mode is enabled.\n */\n private printDebugItems(): void {\n if (this.config.debug) {\n for (const item of this.context.debugItems) {\n console.log(item);\n }\n }\n }\n\n /**\n * Checks if the current message matches any of the configured patterns.\n * Supports both string and RegExp patterns.\n *\n * @returns true if any pattern matches, false otherwise\n */\n private checkMessagePatterns(): boolean {\n if (!this.config.messages?.length) {\n return false;\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);\n }\n\n for (const pattern of this.config.messages) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);\n }\n\n const matches =\n typeof pattern === \"string\" ? this.context.message.includes(pattern) : pattern.test(this.context.message);\n\n if (matches) {\n this.context.debugItems.push(\"[filter-plugin] pattern match: true\");\n return true;\n }\n\n this.context.debugItems.push(\"[filter-plugin] pattern match: false\");\n }\n\n return false;\n }\n\n /**\n * Checks if the current message matches any of the configured queries.\n * Uses @jsonquerylang/jsonquery for query execution.\n *\n * @returns true if any query matches, false otherwise\n */\n private checkQueries(): boolean {\n if (!this.config.queries?.length) {\n return false;\n }\n\n const queryContext = {\n level: this.context.logLevel,\n message: this.context.message,\n data: this.context.data,\n };\n\n try {\n // Process each query individually and return true if any match\n for (const q of this.config.queries) {\n // Split OR conditions and wrap each in filter()\n const conditions = q.split(\" or \").map((cond) => `filter(${cond.trim().replaceAll(`'`, `\"`)})`);\n const query = conditions.join(\" or \");\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);\n this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n }\n\n // Try each condition separately\n for (const condition of conditions) {\n try {\n const output = jsonquery([queryContext], condition) as Array<any>;\n if (output.length > 0) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);\n }\n return true;\n }\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] query: ${condition}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n // Continue trying other conditions\n }\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(\"[filter-plugin] query match: false\");\n }\n }\n\n return false;\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n return false;\n }\n }\n\n /**\n * Checks if a log message should be allowed based on the configured filters.\n *\n * The filtering logic is:\n * 1. If no filters defined, allow all logs\n * 2. If message patterns match, allow the log\n * 3. If queries match, allow the log\n * 4. Otherwise, filter out the log\n *\n * @param params - The log message parameters\n * @returns true if the log should be allowed, false otherwise\n */\n check(params: PluginShouldSendToLoggerParams): boolean {\n this.resetContext(params);\n\n // If no filters defined at all, allow everything\n if (!this.config.messages?.length && !this.config.queries?.length) {\n this.context.debugItems.push(\"[filter-plugin] no filters defined, allowing message\");\n this.printDebugItems();\n return true;\n }\n\n // Check message patterns first\n if (this.checkMessagePatterns()) {\n this.printDebugItems();\n return true;\n }\n\n // Then check queries if message patterns didn't match\n const queryResult = this.checkQueries();\n this.printDebugItems();\n return queryResult;\n }\n}\n","import type { LogLayerPlugin, PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport { FilterExecutor } from \"./FilterExecutor.js\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Creates a new filter plugin instance.\n *\n * The filter plugin allows filtering log messages based on:\n * - String patterns\n * - Regular expressions\n * - JSON queries\n *\n * @example\n * ```typescript\n * // Filter error messages\n * const filter = filterPlugin({\n * messages: ['error'],\n * });\n *\n * // Filter by log level\n * const levelFilter = filterPlugin({\n * queries: ['.level == \"error\" or .level == \"warn\"'],\n * });\n * ```\n *\n * @param config - The filter plugin configuration\n * @returns A LogLayer plugin instance\n */\nexport function filterPlugin(config: filterPluginParams): LogLayerPlugin {\n const executor = new FilterExecutor(config);\n\n return {\n id: config.id,\n disabled: config.disabled,\n shouldSendToLogger: (params: PluginShouldSendToLoggerParams) => {\n return executor.check(params);\n },\n };\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAyBnB,IAAM,iBAAN,MAAqB;AAAA,EACT;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOR,YAAY,QAA4B;AACtC,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,MACb,SAAS;AAAA,MACT,UAAU;AAAA,MACV,MAAM,CAAC;AAAA,MACP,YAAY,CAAC;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,aAAa,QAA8C;AACjE,SAAK,UAAU;AAAA,MACb,SAAS,OAAO,UAAU,KAAK,GAAG,KAAK;AAAA,MACvC,UAAU,OAAO;AAAA,MACjB,MAAM,OAAO,QAAQ,CAAC;AAAA,MACtB,YAAY,CAAC,mDAAmD;AAAA,IAClE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,kBAAwB;AAC9B,QAAI,KAAK,OAAO,OAAO;AACrB,iBAAW,QAAQ,KAAK,QAAQ,YAAY;AAC1C,gBAAQ,IAAI,IAAI;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAAA;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ACvE,QAAM,WAAW,IAAI,eAAe,MAAM;AAE1C,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,UAAU,OAAO;AAAA,IACjB,oBAAoB,CAAC,WAA2C;AAC9D,aAAO,SAAS,MAAM,MAAM;AAAA,IAC9B;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/FilterExecutor.ts","../src/plugin.ts"],"sourcesContent":["import { jsonquery } from \"@jsonquerylang/jsonquery\";\nimport type { PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Internal context for the filter execution.\n * Contains the current log message details and debug information.\n */\ninterface FilterContext {\n /** The combined log message */\n message: string;\n /** The log level */\n logLevel: string;\n /** Additional log data */\n data: Record<string, any>;\n /** Debug messages for troubleshooting */\n debugItems: string[];\n}\n\n/**\n * Core filtering logic implementation.\n * Handles pattern matching and query-based filtering of log messages.\n *\n * @internal\n */\nexport class FilterExecutor {\n private readonly config: filterPluginParams;\n private context: FilterContext;\n\n /**\n * Creates a new FilterExecutor instance.\n *\n * @param config - The filter plugin configuration\n */\n constructor(config: filterPluginParams) {\n this.config = config;\n this.context = {\n message: \"\",\n logLevel: \"\",\n data: {},\n debugItems: [],\n };\n }\n\n /**\n * Resets the context for a new log message check.\n *\n * @param params - The log message parameters\n */\n private resetContext(params: PluginShouldSendToLoggerParams): void {\n this.context = {\n message: params.messages?.join(\" \") || \"\",\n logLevel: params.logLevel,\n data: params.data || {},\n debugItems: [\"[filter-plugin] =================================\"],\n };\n }\n\n /**\n * Prints debug information if debug mode is enabled.\n */\n private printDebugItems(): void {\n if (this.config.debug) {\n for (const item of this.context.debugItems) {\n console.log(item);\n }\n }\n }\n\n /**\n * Checks if the current message matches any of the configured patterns.\n * Supports both string and RegExp patterns.\n *\n * @returns true if any pattern matches, false otherwise\n */\n private checkMessagePatterns(): boolean {\n if (!this.config.messages?.length) {\n return false;\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] message: ${this.context.message}`);\n }\n\n for (const pattern of this.config.messages) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] pattern: ${pattern}`);\n }\n\n const matches =\n typeof pattern === \"string\" ? this.context.message.includes(pattern) : pattern.test(this.context.message);\n\n if (matches) {\n this.context.debugItems.push(\"[filter-plugin] pattern match: true\");\n return true;\n }\n\n this.context.debugItems.push(\"[filter-plugin] pattern match: false\");\n }\n\n return false;\n }\n\n /**\n * Checks if the current message matches any of the configured queries.\n * Uses @jsonquerylang/jsonquery for query execution.\n *\n * @returns true if any query matches, false otherwise\n */\n private checkQueries(): boolean {\n if (!this.config.queries?.length) {\n return false;\n }\n\n const queryContext = {\n level: this.context.logLevel,\n message: this.context.message,\n data: this.context.data,\n };\n\n try {\n // Process each query individually and return true if any match\n for (const q of this.config.queries) {\n // Split OR conditions and wrap each in filter()\n const conditions = q.split(\" or \").map((cond) => `filter(${cond.trim().replaceAll(`'`, `\"`)})`);\n const query = conditions.join(\" or \");\n\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query: filter(${query})`);\n this.context.debugItems.push(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n }\n\n // Try each condition separately\n for (const condition of conditions) {\n try {\n const output = jsonquery([queryContext], condition) as Array<any>;\n if (output.length > 0) {\n if (this.config.debug) {\n this.context.debugItems.push(`[filter-plugin] query match: ${output.length > 0}`);\n }\n return true;\n }\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] query: ${condition}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n // Continue trying other conditions\n }\n }\n\n if (this.config.debug) {\n this.context.debugItems.push(\"[filter-plugin] query match: false\");\n }\n }\n\n return false;\n } catch (e) {\n console.error(`[filter-plugin] Error: ${e}`);\n console.log(`[filter-plugin] queries: ${JSON.stringify(this.config.queries)}`);\n console.log(`[filter-plugin] input: ${JSON.stringify(queryContext)}`);\n return false;\n }\n }\n\n /**\n * Checks if a log message should be allowed based on the configured filters.\n *\n * The filtering logic is:\n * 1. If no filters defined, allow all logs\n * 2. If message patterns match, allow the log\n * 3. If queries match, allow the log\n * 4. Otherwise, filter out the log\n *\n * @param params - The log message parameters\n * @returns true if the log should be allowed, false otherwise\n */\n check(params: PluginShouldSendToLoggerParams): boolean {\n this.resetContext(params);\n\n // If no filters defined at all, allow everything\n if (!this.config.messages?.length && !this.config.queries?.length) {\n this.context.debugItems.push(\"[filter-plugin] no filters defined, allowing message\");\n this.printDebugItems();\n return true;\n }\n\n // Check message patterns first\n if (this.checkMessagePatterns()) {\n this.printDebugItems();\n return true;\n }\n\n // Then check queries if message patterns didn't match\n const queryResult = this.checkQueries();\n this.printDebugItems();\n return queryResult;\n }\n}\n","import type { LogLayerPlugin, PluginShouldSendToLoggerParams } from \"@loglayer/plugin\";\nimport { FilterExecutor } from \"./FilterExecutor.js\";\nimport type { filterPluginParams } from \"./types.js\";\n\n/**\n * Creates a new filter plugin instance.\n *\n * The filter plugin allows filtering log messages based on:\n * - String patterns\n * - Regular expressions\n * - JSON queries\n *\n * @example\n * ```typescript\n * // Filter error messages\n * const filter = filterPlugin({\n * messages: ['error'],\n * });\n *\n * // Filter by log level\n * const levelFilter = filterPlugin({\n * queries: ['.level == \"error\" or .level == \"warn\"'],\n * });\n * ```\n *\n * @param config - The filter plugin configuration\n * @returns A LogLayer plugin instance\n */\nexport function filterPlugin(config: filterPluginParams): LogLayerPlugin {\n const executor = new FilterExecutor(config);\n\n return {\n id: config.id,\n disabled: config.disabled,\n shouldSendToLogger: (params: PluginShouldSendToLoggerParams) => {\n return executor.check(params);\n },\n };\n}\n"],"mappings":";;;;;;;;;AAyBA,IAAa,iBAAb,MAA4B;CAC1B,AAAiB;CACjB,AAAQ;;;;;;CAOR,YAAY,QAA4B;AACtC,OAAK,SAAS;AACd,OAAK,UAAU;GACb,SAAS;GACT,UAAU;GACV,MAAM,EAAE;GACR,YAAY,EAAE;GACf;;;;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,7 +1,7 @@
1
1
  {
2
2
  "name": "@loglayer/plugin-filter",
3
3
  "description": "Filter logs with LogLayer using string patterns, regular expressions, or JSON Queries.",
4
- "version": "3.0.4",
4
+ "version": "3.0.5",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -33,16 +33,16 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@jsonquerylang/jsonquery": "5.0.4",
36
- "@loglayer/plugin": "2.1.5",
37
- "@loglayer/shared": "2.5.2"
36
+ "@loglayer/plugin": "2.1.6",
37
+ "@loglayer/shared": "2.5.3"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/node": "24.6.1",
41
- "tsup": "8.5.0",
40
+ "@types/node": "24.7.2",
41
+ "tsdown": "0.15.7",
42
42
  "typescript": "5.9.3",
43
43
  "vitest": "3.2.4",
44
- "loglayer": "6.8.2",
45
- "@internal/tsconfig": "2.1.0"
44
+ "@internal/tsconfig": "2.1.0",
45
+ "loglayer": "6.9.1"
46
46
  },
47
47
  "bugs": "https://github.com/loglayer/loglayer/issues",
48
48
  "engines": {
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "homepage": "https://loglayer.dev",
55
55
  "scripts": {
56
- "build": "tsup src/index.ts",
56
+ "build": "tsdown src/index.ts",
57
57
  "test": "vitest --run",
58
58
  "clean": "rm -rf .turbo node_modules dist",
59
59
  "lint": "biome check --no-errors-on-unmatched --write --unsafe src",