@jmlq/logger 0.1.0-alpha.14 → 0.1.0-alpha.16

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.
@@ -6,7 +6,6 @@ export declare class DataSourceService implements ILogDatasource {
6
6
  private readonly targets;
7
7
  private readonly onError?;
8
8
  readonly name = "composite";
9
- private logs;
10
9
  constructor(targets: ILogDatasource[], onError?: DataSourceErrorHandler | undefined);
11
10
  private handleError;
12
11
  save(log: ILogProps): Promise<void>;
@@ -6,7 +6,6 @@ class DataSourceService {
6
6
  this.targets = targets;
7
7
  this.onError = onError;
8
8
  this.name = "composite";
9
- this.logs = [];
10
9
  this.targets = (targets ?? []).filter(Boolean);
11
10
  }
12
11
  handleError(op, i, reason) {
@@ -30,48 +29,48 @@ class DataSourceService {
30
29
  }
31
30
  });
32
31
  }
33
- // async find(filter?: IGetLogsFilterProps) {
34
- // const results = await Promise.allSettled(
35
- // this.targets.map((ds) => ds.find?.(filter))
36
- // );
37
- // const logs: ILogResponse[] = [];
38
- // results.forEach((r, i) => {
39
- // if (r.status === "fulfilled" && Array.isArray(r.value)) {
40
- // logs.push(...r.value);
41
- // } else if (r.status === "rejected") {
42
- // this.handleError("find", i, r.reason);
43
- // }
44
- // });
45
- // logs.sort((a, b) => b.timestamp - a.timestamp);
46
- // return logs;
47
- // }
48
32
  async find(filter) {
49
- let results = [...this.logs];
50
- if (filter?.levelMin !== undefined) {
51
- results = results.filter((log) => log.level >= filter.levelMin);
52
- }
53
- if (filter?.since !== undefined) {
54
- results = results.filter((log) => log.timestamp >= filter.since);
55
- }
56
- if (filter?.until !== undefined) {
57
- results = results.filter((log) => log.timestamp <= filter.until);
58
- }
59
- if (filter?.query) {
60
- const q = filter.query.toLowerCase();
61
- results = results.filter((log) => {
62
- const msg = typeof log.message === "string"
63
- ? log.message.toLowerCase()
64
- : JSON.stringify(log.message).toLowerCase();
65
- return msg.includes(q);
66
- });
67
- }
68
- // Ordenar por timestamp ascendente (opcional pero útil para visualizar)
69
- results.sort((a, b) => a.timestamp - b.timestamp);
70
- // Paginación
71
- const offset = filter?.offset ?? 0;
72
- const limit = filter?.limit ?? results.length;
73
- return results.slice(offset, offset + limit);
33
+ const results = await Promise.allSettled(this.targets.map((ds) => ds.find?.(filter)));
34
+ const logs = [];
35
+ results.forEach((r, i) => {
36
+ if (r.status === "fulfilled" && Array.isArray(r.value)) {
37
+ logs.push(...r.value);
38
+ }
39
+ else if (r.status === "rejected") {
40
+ this.handleError("find", i, r.reason);
41
+ }
42
+ });
43
+ logs.sort((a, b) => b.timestamp - a.timestamp);
44
+ return logs;
74
45
  }
46
+ // async find(filter?: IGetLogsFilterProps): Promise<ILogResponse[]> {
47
+ // let results = [...this.logs];
48
+ // if (filter?.levelMin !== undefined) {
49
+ // results = results.filter((log) => log.level >= filter.levelMin!);
50
+ // }
51
+ // if (filter?.since !== undefined) {
52
+ // results = results.filter((log) => log.timestamp >= filter.since!);
53
+ // }
54
+ // if (filter?.until !== undefined) {
55
+ // results = results.filter((log) => log.timestamp <= filter.until!);
56
+ // }
57
+ // if (filter?.query) {
58
+ // const q = filter.query.toLowerCase();
59
+ // results = results.filter((log) => {
60
+ // const msg =
61
+ // typeof log.message === "string"
62
+ // ? log.message.toLowerCase()
63
+ // : JSON.stringify(log.message).toLowerCase();
64
+ // return msg.includes(q);
65
+ // });
66
+ // }
67
+ // // Ordenar por timestamp ascendente (opcional pero útil para visualizar)
68
+ // results.sort((a, b) => a.timestamp - b.timestamp);
69
+ // // Paginación
70
+ // const offset = filter?.offset ?? 0;
71
+ // const limit = filter?.limit ?? results.length;
72
+ // return results.slice(offset, offset + limit);
73
+ // }
75
74
  async flush() {
76
75
  const results = await Promise.allSettled(this.targets.map((ds) => ds.flush?.()));
77
76
  results.forEach((r, i) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jmlq/logger",
3
3
  "description": "logger package with clean architecture",
4
- "version": "0.1.0-alpha.14",
4
+ "version": "0.1.0-alpha.16",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {