analogger 1.37.0 → 2.0.0
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/README.md +168 -1
- package/ana-logger.d.cts +29 -4
- package/browser/ana-logger.mjs +342 -28
- package/demo.cjs +53 -1
- package/dist/analogger-browser.min.mjs +8 -5
- package/dist/html-to-image-plugin.min.mjs +8 -5
- package/esm/ana-logger.mjs +342 -28
- package/package.json +1 -1
- package/src/ana-logger.cjs +345 -28
package/README.md
CHANGED
|
@@ -793,7 +793,7 @@ anaLogger.setActiveTarget(process.env.DEVELOPER); // <= Assuming it has been
|
|
|
793
793
|
<br/>
|
|
794
794
|
|
|
795
795
|
> Note that two targets cannot be overridden: {ALL: "ALL", USER: "USER"}.
|
|
796
|
-
The system always adds them to the allowed list, so they will still be set even if a call to setTargets() is empty.
|
|
796
|
+
> The system always adds them to the allowed list, so they will still be set even if a call to setTargets() is empty.
|
|
797
797
|
|
|
798
798
|
```javascript
|
|
799
799
|
// Two implicit targets "ALL" and "USER"
|
|
@@ -804,6 +804,173 @@ analogger.setTargets()
|
|
|
804
804
|
|
|
805
805
|
---
|
|
806
806
|
|
|
807
|
+
### loadLids()
|
|
808
|
+
|
|
809
|
+
#### Context
|
|
810
|
+
|
|
811
|
+
## Using `loadLids` for Predefined Log Messages
|
|
812
|
+
|
|
813
|
+
The `loadLids` method allows you to register a collection of predefined log message templates, identified by unique Log IDs (Lids). This promotes consistency and simplifies logging by allowing you to reference these templates instead of writing out full messages repeatedly.
|
|
814
|
+
|
|
815
|
+
### Example
|
|
816
|
+
|
|
817
|
+
With `loadLids`, you can define a set of log messages that can be reused throughout your application.
|
|
818
|
+
Instead of scattered, repetitive messages, Log IDs (lid) offer clear, centralized definitions.
|
|
819
|
+
|
|
820
|
+
```javascript
|
|
821
|
+
// lids.js
|
|
822
|
+
const LIDS = {
|
|
823
|
+
API35390: {
|
|
824
|
+
message: "API logging initialized",
|
|
825
|
+
contextName: "TEST",
|
|
826
|
+
color : "green",
|
|
827
|
+
symbol : "check"
|
|
828
|
+
},
|
|
829
|
+
API35391: {
|
|
830
|
+
message: "Error API logging initialized",
|
|
831
|
+
},
|
|
832
|
+
API65341: {
|
|
833
|
+
message: "The username doesn't match the userID: {{username1}} !== {{username2}}"
|
|
834
|
+
},
|
|
835
|
+
AUTH1001: {
|
|
836
|
+
message: "Authentication failed for user: {{username}}",
|
|
837
|
+
color: "red",
|
|
838
|
+
symbol: "alert"
|
|
839
|
+
},
|
|
840
|
+
DB205: {
|
|
841
|
+
message: "Database query took {{duration}}ms"
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
module.exports = LIDS;
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
```javascript
|
|
850
|
+
// main.js
|
|
851
|
+
const {anaLogger} = require("analogger");
|
|
852
|
+
const ligs = require("./lids.js");
|
|
853
|
+
anaLogger.loadLids(LIDS);
|
|
854
|
+
|
|
855
|
+
anaLogger.log({lid: "API35390", color: "green"}, "API logging about to be initialized");
|
|
856
|
+
// => DEFAULT: (API35390) ✔ API logging about to be initialized
|
|
857
|
+
|
|
858
|
+
anaLogger.log(LIDS.API35390);
|
|
859
|
+
// => TEST: (API35390) ✔ API logging initialized
|
|
860
|
+
|
|
861
|
+
anaLogger.error(LIDS.API35391);
|
|
862
|
+
// => ERROR: (API35391) ❌ Error API logging initialized
|
|
863
|
+
|
|
864
|
+
anaLogger.log(LIDS.API65341, {username1: "test", username2: "test2"});
|
|
865
|
+
// => DEFAULT: (API65341) ✔ The username doesn't match the userID: test !== test2
|
|
866
|
+
|
|
867
|
+
anaLogger.log(LIDS.API65341, "Some other messages");
|
|
868
|
+
// => DEFAULT: (API65341) ✔ The username doesn't match the userID: {{username1}} !== {{username2}}•Some other messages
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
<br/>
|
|
872
|
+
|
|
873
|
+
---
|
|
874
|
+
### getLids
|
|
875
|
+
|
|
876
|
+
Returns all loaded lids
|
|
877
|
+
|
|
878
|
+
```javascript
|
|
879
|
+
const lids = anaLogger.getLids();
|
|
880
|
+
|
|
881
|
+
{
|
|
882
|
+
API35390: {
|
|
883
|
+
message: 'API logging initialized',
|
|
884
|
+
contextName: 'TEST',
|
|
885
|
+
color: 'green',
|
|
886
|
+
symbol: 'check',
|
|
887
|
+
lid: 'API35390',
|
|
888
|
+
callCount: 2,
|
|
889
|
+
callTimes: [ 1745412629482, 1745412629504 ],
|
|
890
|
+
target: [ 'ALL', 'USER', 'NONE' ],
|
|
891
|
+
dates: [ '2025-04-23 13:50:29.482', '2025-04-23 13:50:29.504' ]
|
|
892
|
+
},
|
|
893
|
+
API35391: {
|
|
894
|
+
message: 'Error API logging initialized',
|
|
895
|
+
lid: 'API35391',
|
|
896
|
+
callCount: 1,
|
|
897
|
+
callTimes: [ 1745412629507 ],
|
|
898
|
+
target: [ 'ALL', 'USER', 'NONE' ],
|
|
899
|
+
dates: [ '2025-04-23 13:50:29.507' ]
|
|
900
|
+
},
|
|
901
|
+
API65341: {
|
|
902
|
+
message: "The username doesn't match the userID: {{username1}} !== {{username2}}",
|
|
903
|
+
lid: 'API65341',
|
|
904
|
+
callCount: 2,
|
|
905
|
+
callTimes: [ 1745412629509, 1745412629510 ],
|
|
906
|
+
target: [ 'ALL', 'USER', 'NONE' ],
|
|
907
|
+
dates: [ '2025-04-23 13:50:29.509', '2025-04-23 13:50:29.510' ]
|
|
908
|
+
},
|
|
909
|
+
WEB35382: {
|
|
910
|
+
message: 'Some log message',
|
|
911
|
+
lid: 'WEB35382',
|
|
912
|
+
callCount: 5,
|
|
913
|
+
callTimes: [
|
|
914
|
+
1745412629511,
|
|
915
|
+
1745412629512,
|
|
916
|
+
1745412629514,
|
|
917
|
+
1745412629515,
|
|
918
|
+
1745412629517
|
|
919
|
+
],
|
|
920
|
+
dates: [
|
|
921
|
+
'2025-04-23 13:50:29.511',
|
|
922
|
+
'2025-04-23 13:50:29.512',
|
|
923
|
+
'2025-04-23 13:50:29.514',
|
|
924
|
+
'2025-04-23 13:50:29.515',
|
|
925
|
+
'2025-04-23 13:50:29.517'
|
|
926
|
+
]
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
<br/>
|
|
935
|
+
|
|
936
|
+
---
|
|
937
|
+
|
|
938
|
+
### forceLid(true);
|
|
939
|
+
|
|
940
|
+
Force the system to generate the lid even if it is not defined
|
|
941
|
+
|
|
942
|
+
```javascript
|
|
943
|
+
anaLogger.forceLid(true);
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
<br/>
|
|
947
|
+
|
|
948
|
+
---
|
|
949
|
+
|
|
950
|
+
### forceResolveErrorLineCall(true);
|
|
951
|
+
|
|
952
|
+
Add the stack trace to the error message context
|
|
953
|
+
|
|
954
|
+
```javascript
|
|
955
|
+
anaLogger.forceResolveErrorLineCall(true);
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
<br/>
|
|
959
|
+
|
|
960
|
+
---
|
|
961
|
+
|
|
962
|
+
### forceResolveLineCall(true);
|
|
963
|
+
|
|
964
|
+
Add the stack trace to the log message context
|
|
965
|
+
|
|
966
|
+
```javascript
|
|
967
|
+
anaLogger.forceResolveLineCall(true);
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
<br/>
|
|
971
|
+
|
|
972
|
+
---
|
|
973
|
+
|
|
807
974
|
|
|
808
975
|
### assert()
|
|
809
976
|
|
package/ana-logger.d.cts
CHANGED
|
@@ -18,6 +18,8 @@ declare class ____AnaLogger {
|
|
|
18
18
|
};
|
|
19
19
|
static instanceCount: number;
|
|
20
20
|
static pluginTable: {};
|
|
21
|
+
static lidTable: {};
|
|
22
|
+
static lidTableOn: boolean;
|
|
21
23
|
static generateInstance(): ____AnaLogger;
|
|
22
24
|
/**
|
|
23
25
|
* Returns an AnaLogger instance
|
|
@@ -53,6 +55,9 @@ declare class ____AnaLogger {
|
|
|
53
55
|
hideHookMessage: boolean;
|
|
54
56
|
};
|
|
55
57
|
originalFormatFunction: string;
|
|
58
|
+
forceLidOn: boolean;
|
|
59
|
+
resolveLineCall: boolean;
|
|
60
|
+
resolveErrorLineCall: boolean;
|
|
56
61
|
errorTargetHandler: any;
|
|
57
62
|
errorUserTargetHandler: any;
|
|
58
63
|
rawLog: any;
|
|
@@ -70,6 +75,17 @@ declare class ____AnaLogger {
|
|
|
70
75
|
};
|
|
71
76
|
getName(): string;
|
|
72
77
|
getId(): string;
|
|
78
|
+
/**
|
|
79
|
+
* For the logger to generate a lid when none is specified
|
|
80
|
+
* @param lidOn
|
|
81
|
+
*/
|
|
82
|
+
forceLid(lidOn?: boolean): void;
|
|
83
|
+
forceResolveLineCall(resolveLineCall?: boolean): void;
|
|
84
|
+
forceResolveErrorLineCall(resolveErrorLineCall?: boolean): void;
|
|
85
|
+
importLids(lids: any): void;
|
|
86
|
+
loadLids(lids: any): void;
|
|
87
|
+
convertTimestampToDate(timestamp: any): string;
|
|
88
|
+
getLids(): {};
|
|
73
89
|
keepLogHistory(): void;
|
|
74
90
|
releaseLogHistory(): void;
|
|
75
91
|
resetLogHistory(): void;
|
|
@@ -287,11 +303,14 @@ declare class ____AnaLogger {
|
|
|
287
303
|
* @returns {*}
|
|
288
304
|
*/
|
|
289
305
|
checkOnLogging(context: any, data: any, extras: any, callbackName: any): any;
|
|
306
|
+
isContextMessagePattern(str: any): boolean;
|
|
307
|
+
transformContextMessage(template: any, data: any): any;
|
|
290
308
|
/**
|
|
291
309
|
* Display log following template
|
|
292
310
|
* @param context
|
|
311
|
+
* @param argsWithoutContext
|
|
293
312
|
*/
|
|
294
|
-
processOutput(context?: {}, ...
|
|
313
|
+
processOutput(context?: {}, ...argsWithoutContext: any[]): void;
|
|
295
314
|
/**
|
|
296
315
|
* Check that a parameter uses the expected AnaLogger format.
|
|
297
316
|
* For this, the first parameter should be an object that contains at least
|
|
@@ -300,14 +319,20 @@ declare class ____AnaLogger {
|
|
|
300
319
|
* @returns {boolean}
|
|
301
320
|
*/
|
|
302
321
|
isExtendedOptionsPassed(options: any): boolean;
|
|
303
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Convert a string to an object by parsing the string
|
|
324
|
+
* and identifying key-value pairs
|
|
325
|
+
* @param str
|
|
326
|
+
* @returns {{}|null}
|
|
327
|
+
*/
|
|
328
|
+
stringToObject(str: any): {} | null;
|
|
304
329
|
/**
|
|
305
330
|
* Convert a string into a Context object if possible
|
|
306
331
|
* TODO: To implement in next version
|
|
307
|
-
* @param str
|
|
308
332
|
* @returns {string}
|
|
333
|
+
* @param input
|
|
309
334
|
*/
|
|
310
|
-
extractContextFromInput(
|
|
335
|
+
extractContextFromInput(input: any): string;
|
|
311
336
|
listSymbols(): void;
|
|
312
337
|
applySymbolByName(context: any): void;
|
|
313
338
|
/**
|