analogger 2.2.1 → 2.3.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 +1 -0
- package/ana-logger.d.cts +5 -14
- package/browser/ana-logger.mjs +99 -21
- package/dist/analogger-browser.min.mjs +6 -6
- package/dist/html-to-image-plugin.min.mjs +6 -6
- package/esm/ana-logger.mjs +99 -21
- package/package.json +1 -1
- package/src/ana-logger.cjs +112 -21
- package/src/ana-logger.d.cts +1 -1
package/README.md
CHANGED
|
@@ -302,6 +302,7 @@ Display the browser native message box if run from it; otherwise, it displays th
|
|
|
302
302
|
| logMaxArchives | 3 | number | _Maximum number of log files to use_ |
|
|
303
303
|
| requiredLogLevel | "LOG" | "LOG" / "INFO" / "WARN" / "ERROR" | _Define the log level from which the system can show a log entry_ |
|
|
304
304
|
| enableDate | false | boolean | _Show date + time (instead of time only)_ |
|
|
305
|
+
| enableMillisec | false | boolean | _Show milliseconds in the log time (e.g., 12:22:04,555)_ |
|
|
305
306
|
| logToLocalStorage | false | boolean | _Persist logs in browser localStorage_ |
|
|
306
307
|
| logToLocalStorageMax | 50 | number | _Max entries to keep in localStorage_ |
|
|
307
308
|
| logToLocalStorageSize | 10000 | number | _Max size in bytes for localStorage logs_ |
|
package/ana-logger.d.cts
CHANGED
|
@@ -54,6 +54,8 @@ declare class ____AnaLogger {
|
|
|
54
54
|
options: {
|
|
55
55
|
hideHookMessage: boolean;
|
|
56
56
|
};
|
|
57
|
+
remoteBuffer: any[];
|
|
58
|
+
remoteTimer: any;
|
|
57
59
|
originalFormatFunction: string;
|
|
58
60
|
forceLidOn: boolean;
|
|
59
61
|
resolveLineCall: boolean;
|
|
@@ -114,10 +116,8 @@ declare class ____AnaLogger {
|
|
|
114
116
|
*/
|
|
115
117
|
isBrowser(): boolean;
|
|
116
118
|
resetLogger(): void;
|
|
117
|
-
remoteBuffer: any[];
|
|
118
|
-
remoteTimer: NodeJS.Timeout;
|
|
119
119
|
resetOptions(): void;
|
|
120
|
-
setOptions({ contextLenMax, idLenMax, lidLenMax, symbolLenMax, enableTrace, messageLenMax, hideLog, hideError, hideHookMessage, hidePassingTests, logToDom, logToFile, logMaxSize, logMaxArchives, logIndexArchive, addArchiveTimestamp, addArchiveIndex, compressArchives, compressionLevel, logToRemote, logToRemoteUrl, logToRemoteBinaryUrl, loopback, requiredLogLevel, oneConsolePerContext, silent, enableDate, logToLocalStorage, logToLocalStorageMax, logToLocalStorageSize, logToRemoteMaxEntries, logToRemoteDebounce, protocol, host, port, pathname, binarypathname, loadHtmlToImage }?: any): void;
|
|
120
|
+
setOptions({ timeLenMax, contextLenMax, idLenMax, lidLenMax, symbolLenMax, enableTrace, messageLenMax, hideLog, hideError, hideHookMessage, hidePassingTests, logToDom, logToFile, logMaxSize, logMaxArchives, logIndexArchive, addArchiveTimestamp, addArchiveIndex, compressArchives, compressionLevel, logToRemote, logToRemoteUrl, logToRemoteBinaryUrl, loopback, requiredLogLevel, oneConsolePerContext, silent, enableDate, enableMillisec, logToLocalStorage, logToLocalStorageMax, logToLocalStorageSize, logToRemoteMaxEntries, logToRemoteDebounce, logToRemoteMaxSize, logToRemoteMinSize, protocol, host, port, pathname, binarypathname, loadHtmlToImage }?: any): void;
|
|
121
121
|
EOL: string;
|
|
122
122
|
updateOptions(options: any): void;
|
|
123
123
|
getOptions(): {
|
|
@@ -131,19 +131,10 @@ declare class ____AnaLogger {
|
|
|
131
131
|
/**
|
|
132
132
|
* Format inputs
|
|
133
133
|
* @see Override {@link setLogFormat}
|
|
134
|
-
* @param contextName
|
|
135
|
-
* @param id
|
|
136
|
-
* @param message
|
|
137
|
-
* @param lid
|
|
138
|
-
* @param symbol
|
|
139
134
|
* @returns {string}
|
|
135
|
+
* @param localContext
|
|
140
136
|
*/
|
|
141
|
-
onBuildLog({
|
|
142
|
-
contextName: any;
|
|
143
|
-
message?: string;
|
|
144
|
-
lid?: string;
|
|
145
|
-
symbol?: string;
|
|
146
|
-
}): string;
|
|
137
|
+
onBuildLog(localContext?: {}): string;
|
|
147
138
|
onErrorForUserTarget(context: any, ...args: any[]): void;
|
|
148
139
|
onError(context: any, ...args: any[]): void;
|
|
149
140
|
/**
|
package/browser/ana-logger.mjs
CHANGED
|
@@ -642,6 +642,9 @@ class ____AnaLogger
|
|
|
642
642
|
hideHookMessage: false
|
|
643
643
|
};
|
|
644
644
|
|
|
645
|
+
remoteBuffer = [];
|
|
646
|
+
remoteTimer = null;
|
|
647
|
+
|
|
645
648
|
static Console = null;
|
|
646
649
|
|
|
647
650
|
#overridenMap = {
|
|
@@ -691,6 +694,9 @@ class ____AnaLogger
|
|
|
691
694
|
this.errorTargetHandler = this.onError.bind(this);
|
|
692
695
|
this.errorUserTargetHandler = this.onErrorForUserTarget.bind(this);
|
|
693
696
|
|
|
697
|
+
this.remoteBuffer = [];
|
|
698
|
+
this.remoteTimer = null;
|
|
699
|
+
|
|
694
700
|
this.setOptions(this.options);
|
|
695
701
|
|
|
696
702
|
if (!____AnaLogger.Console) {
|
|
@@ -899,7 +905,7 @@ class ____AnaLogger
|
|
|
899
905
|
resetLogger()
|
|
900
906
|
{
|
|
901
907
|
this.options = {};
|
|
902
|
-
this.options.timeLenMax =
|
|
908
|
+
this.options.timeLenMax = 8;
|
|
903
909
|
this.options.contextLenMax = 10;
|
|
904
910
|
this.options.idLenMax = 5;
|
|
905
911
|
this.options.lidLenMax = 6;
|
|
@@ -928,11 +934,14 @@ class ____AnaLogger
|
|
|
928
934
|
this.options.pathname = undefined;
|
|
929
935
|
this.options.binarypathname = undefined;
|
|
930
936
|
this.options.enableDate = undefined;
|
|
937
|
+
this.options.enableMillisec = undefined;
|
|
931
938
|
this.options.logToLocalStorage = undefined;
|
|
932
939
|
this.options.logToLocalStorageMax = 50;
|
|
933
940
|
this.options.logToLocalStorageSize = 10000;
|
|
934
941
|
this.options.logToRemoteMaxEntries = undefined;
|
|
935
942
|
this.options.logToRemoteDebounce = undefined;
|
|
943
|
+
this.options.logToRemoteMaxSize = undefined;
|
|
944
|
+
this.options.logToRemoteMinSize = undefined;
|
|
936
945
|
this.remoteBuffer = [];
|
|
937
946
|
this.remoteTimer = null;
|
|
938
947
|
}
|
|
@@ -943,6 +952,7 @@ class ____AnaLogger
|
|
|
943
952
|
}
|
|
944
953
|
|
|
945
954
|
setOptions({
|
|
955
|
+
timeLenMax = undefined,
|
|
946
956
|
contextLenMax = 10,
|
|
947
957
|
idLenMax = 5,
|
|
948
958
|
lidLenMax = 6,
|
|
@@ -970,11 +980,14 @@ class ____AnaLogger
|
|
|
970
980
|
oneConsolePerContext = undefined,
|
|
971
981
|
silent = undefined,
|
|
972
982
|
enableDate = undefined,
|
|
983
|
+
enableMillisec = undefined,
|
|
973
984
|
logToLocalStorage = undefined,
|
|
974
985
|
logToLocalStorageMax = 50,
|
|
975
986
|
logToLocalStorageSize = 10000,
|
|
976
987
|
logToRemoteMaxEntries = undefined,
|
|
977
988
|
logToRemoteDebounce = undefined,
|
|
989
|
+
logToRemoteMaxSize = undefined,
|
|
990
|
+
logToRemoteMinSize = undefined,
|
|
978
991
|
/** Remote - all optional **/
|
|
979
992
|
protocol = undefined,
|
|
980
993
|
host = undefined,
|
|
@@ -990,6 +1003,9 @@ class ____AnaLogger
|
|
|
990
1003
|
this.options.messageLenMax = messageLenMax;
|
|
991
1004
|
this.options.symbolLenMax = symbolLenMax;
|
|
992
1005
|
|
|
1006
|
+
this.options.enableMillisec = enableMillisec;
|
|
1007
|
+
this.options.timeLenMax = timeLenMax;
|
|
1008
|
+
|
|
993
1009
|
this.options.logMaxSize = logMaxSize;
|
|
994
1010
|
this.options.logMaxArchives = logMaxArchives;
|
|
995
1011
|
this.options.logIndexArchive = logIndexArchive;
|
|
@@ -1001,10 +1017,23 @@ class ____AnaLogger
|
|
|
1001
1017
|
this.options.requiredLogLevel = requiredLogLevel;
|
|
1002
1018
|
this.options.enableTrace = enableTrace;
|
|
1003
1019
|
|
|
1020
|
+
this.options.enableMillisec = enableMillisec;
|
|
1021
|
+
if (this.options.enableMillisec)
|
|
1022
|
+
{
|
|
1023
|
+
this.options.timeLenMax += 4;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1004
1026
|
this.options.logToLocalStorageMax = logToLocalStorageMax;
|
|
1005
1027
|
this.options.logToLocalStorageSize = logToLocalStorageSize;
|
|
1028
|
+
|
|
1029
|
+
// Remote logging options
|
|
1030
|
+
this.options.logToRemote = logToRemote;
|
|
1031
|
+
this.options.logToRemoteUrl = logToRemoteUrl;
|
|
1032
|
+
this.options.logToRemoteBinaryUrl = logToRemoteBinaryUrl;
|
|
1006
1033
|
this.options.logToRemoteMaxEntries = logToRemoteMaxEntries;
|
|
1007
1034
|
this.options.logToRemoteDebounce = logToRemoteDebounce;
|
|
1035
|
+
this.options.logToRemoteMaxSize = logToRemoteMaxSize;
|
|
1036
|
+
this.options.logToRemoteMinSize = logToRemoteMinSize;
|
|
1008
1037
|
|
|
1009
1038
|
if (loadHtmlToImage) {
|
|
1010
1039
|
const code = getHtmlToImage();
|
|
@@ -1062,6 +1091,19 @@ class ____AnaLogger
|
|
|
1062
1091
|
}
|
|
1063
1092
|
});
|
|
1064
1093
|
|
|
1094
|
+
if (this.options.enableDate && this.options.timeLenMax === undefined) {
|
|
1095
|
+
this.options.timeLenMax = 17;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
if (this.options.timeLenMax === undefined) {
|
|
1099
|
+
if (this.options.enableDate) {
|
|
1100
|
+
this.options.timeLenMax = 17;
|
|
1101
|
+
}
|
|
1102
|
+
else {
|
|
1103
|
+
this.options.timeLenMax = 8;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1065
1107
|
if (this.options.logToRemote && !this.options.logToRemoteUrl)
|
|
1066
1108
|
{
|
|
1067
1109
|
this.options.logToRemoteUrl = this.convertToUrl({
|
|
@@ -1135,17 +1177,14 @@ class ____AnaLogger
|
|
|
1135
1177
|
/**
|
|
1136
1178
|
* Format inputs
|
|
1137
1179
|
* @see Override {@link setLogFormat}
|
|
1138
|
-
* @param contextName
|
|
1139
|
-
* @param id
|
|
1140
|
-
* @param message
|
|
1141
|
-
* @param lid
|
|
1142
|
-
* @param symbol
|
|
1143
1180
|
* @returns {string}
|
|
1181
|
+
* @param localContext
|
|
1144
1182
|
*/
|
|
1145
|
-
onBuildLog(
|
|
1183
|
+
onBuildLog(localContext = {})
|
|
1146
1184
|
{
|
|
1147
1185
|
try
|
|
1148
1186
|
{
|
|
1187
|
+
let {contextName, message = "", lid = "", symbol = ""} = localContext;
|
|
1149
1188
|
let strResult = "";
|
|
1150
1189
|
|
|
1151
1190
|
const strs = message.split(/\n/g);
|
|
@@ -1158,14 +1197,22 @@ class ____AnaLogger
|
|
|
1158
1197
|
const now = new Date();
|
|
1159
1198
|
let time = ("0" + now.getHours()).slice(-2) + ":" + ("0" + now.getMinutes()).slice(-2) + ":" + ("0" + now.getSeconds()).slice(-2);
|
|
1160
1199
|
|
|
1161
|
-
|
|
1200
|
+
const enableMillisec = localContext.hasOwnProperty("enableMillisec") ? localContext.enableMillisec : this.options.enableMillisec;
|
|
1201
|
+
if (enableMillisec)
|
|
1202
|
+
{
|
|
1203
|
+
time += "," + ("00" + now.getMilliseconds()).slice(-3);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
const enableDate = localContext.hasOwnProperty("enableDate") ? localContext.enableDate : this.options.enableDate;
|
|
1207
|
+
if (enableDate)
|
|
1162
1208
|
{
|
|
1163
1209
|
let date = now.getFullYear().toString().slice(-2) + "-" + (now.getMonth() + 1).toString().padStart(2, "0") + "-" + now.getDate().toString().padStart(2, "0");
|
|
1164
1210
|
time = date + " " + time;
|
|
1165
1211
|
}
|
|
1166
1212
|
|
|
1167
1213
|
// Display content in columns
|
|
1168
|
-
|
|
1214
|
+
const timeLenMax = localContext.hasOwnProperty("timeLenMax") ? localContext.timeLenMax : this.options.timeLenMax;
|
|
1215
|
+
time = this.truncateMessage(time, {fit: timeLenMax});
|
|
1169
1216
|
|
|
1170
1217
|
if (i > 0)
|
|
1171
1218
|
{
|
|
@@ -1178,7 +1225,8 @@ class ____AnaLogger
|
|
|
1178
1225
|
});
|
|
1179
1226
|
lid = this.truncateMessage(lid, {fit: this.options.lidLenMax});
|
|
1180
1227
|
|
|
1181
|
-
|
|
1228
|
+
const messageLenMax = localContext.hasOwnProperty("messageLenMax") ? localContext.messageLenMax : this.options.messageLenMax;
|
|
1229
|
+
if (messageLenMax !== undefined)
|
|
1182
1230
|
{
|
|
1183
1231
|
message0 = this.truncateMessage(message0, {fit: this.options.messageLenMax});
|
|
1184
1232
|
}
|
|
@@ -2000,18 +2048,31 @@ class ____AnaLogger
|
|
|
2000
2048
|
{
|
|
2001
2049
|
try
|
|
2002
2050
|
{
|
|
2003
|
-
if (this.options.logToRemoteMaxEntries === undefined && this.options.logToRemoteDebounce === undefined)
|
|
2051
|
+
if (this.options.logToRemoteMaxEntries === undefined && this.options.logToRemoteDebounce === undefined && this.options.logToRemoteMaxSize === undefined)
|
|
2004
2052
|
{
|
|
2005
2053
|
this.performRemotePost([...data]);
|
|
2006
2054
|
return;
|
|
2007
2055
|
}
|
|
2008
2056
|
|
|
2009
|
-
this.remoteBuffer
|
|
2010
|
-
|
|
2011
|
-
if (this.options.logToRemoteMaxEntries !== undefined && this.remoteBuffer.length >= this.options.logToRemoteMaxEntries)
|
|
2057
|
+
if (Array.isArray(this.remoteBuffer))
|
|
2012
2058
|
{
|
|
2013
|
-
this.
|
|
2014
|
-
|
|
2059
|
+
this.remoteBuffer.push([...data]);
|
|
2060
|
+
|
|
2061
|
+
if (this.options.logToRemoteMaxEntries !== undefined && this.remoteBuffer.length >= this.options.logToRemoteMaxEntries)
|
|
2062
|
+
{
|
|
2063
|
+
this.flushRemoteLogs();
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
if (this.options.logToRemoteMaxSize !== undefined)
|
|
2068
|
+
{
|
|
2069
|
+
const currentSize = JSON.stringify(this.remoteBuffer).length;
|
|
2070
|
+
if (currentSize >= this.options.logToRemoteMaxSize)
|
|
2071
|
+
{
|
|
2072
|
+
this.flushRemoteLogs();
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2015
2076
|
}
|
|
2016
2077
|
|
|
2017
2078
|
if (this.options.logToRemoteDebounce !== undefined && !this.remoteTimer)
|
|
@@ -2031,15 +2092,32 @@ class ____AnaLogger
|
|
|
2031
2092
|
|
|
2032
2093
|
flushRemoteLogs()
|
|
2033
2094
|
{
|
|
2034
|
-
if (this.
|
|
2095
|
+
if (this.remoteBuffer.length === 0)
|
|
2035
2096
|
{
|
|
2036
|
-
|
|
2037
|
-
this.remoteTimer = null;
|
|
2097
|
+
return;
|
|
2038
2098
|
}
|
|
2039
2099
|
|
|
2040
|
-
if (this.
|
|
2100
|
+
if (this.options.logToRemoteMinSize !== undefined)
|
|
2041
2101
|
{
|
|
2042
|
-
|
|
2102
|
+
const currentSize = JSON.stringify(this.remoteBuffer).length;
|
|
2103
|
+
if (currentSize < this.options.logToRemoteMinSize)
|
|
2104
|
+
{
|
|
2105
|
+
// If we haven't reached min size, and there's no timer, start one if debounce is set
|
|
2106
|
+
if (this.options.logToRemoteDebounce !== undefined && !this.remoteTimer)
|
|
2107
|
+
{
|
|
2108
|
+
this.remoteTimer = setTimeout(() =>
|
|
2109
|
+
{
|
|
2110
|
+
this.flushRemoteLogs();
|
|
2111
|
+
}, this.options.logToRemoteDebounce);
|
|
2112
|
+
}
|
|
2113
|
+
return;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
if (this.remoteTimer)
|
|
2118
|
+
{
|
|
2119
|
+
clearTimeout(this.remoteTimer);
|
|
2120
|
+
this.remoteTimer = null;
|
|
2043
2121
|
}
|
|
2044
2122
|
|
|
2045
2123
|
const dataToFlush = [...this.remoteBuffer];
|