analogger 2.2.2 → 2.3.1
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 +3 -12
- package/browser/ana-logger.mjs +87 -17
- package/dist/analogger-browser.min.mjs +7 -7
- package/dist/html-to-image-plugin.min.mjs +7 -7
- package/esm/ana-logger.mjs +87 -17
- package/package.json +1 -1
- package/src/ana-logger.cjs +134 -18
- 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
|
@@ -117,7 +117,7 @@ declare class ____AnaLogger {
|
|
|
117
117
|
isBrowser(): boolean;
|
|
118
118
|
resetLogger(): void;
|
|
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
|
@@ -905,7 +905,7 @@ class ____AnaLogger
|
|
|
905
905
|
resetLogger()
|
|
906
906
|
{
|
|
907
907
|
this.options = {};
|
|
908
|
-
this.options.timeLenMax =
|
|
908
|
+
this.options.timeLenMax = 8;
|
|
909
909
|
this.options.contextLenMax = 10;
|
|
910
910
|
this.options.idLenMax = 5;
|
|
911
911
|
this.options.lidLenMax = 6;
|
|
@@ -934,11 +934,14 @@ class ____AnaLogger
|
|
|
934
934
|
this.options.pathname = undefined;
|
|
935
935
|
this.options.binarypathname = undefined;
|
|
936
936
|
this.options.enableDate = undefined;
|
|
937
|
+
this.options.enableMillisec = undefined;
|
|
937
938
|
this.options.logToLocalStorage = undefined;
|
|
938
939
|
this.options.logToLocalStorageMax = 50;
|
|
939
940
|
this.options.logToLocalStorageSize = 10000;
|
|
940
941
|
this.options.logToRemoteMaxEntries = undefined;
|
|
941
942
|
this.options.logToRemoteDebounce = undefined;
|
|
943
|
+
this.options.logToRemoteMaxSize = undefined;
|
|
944
|
+
this.options.logToRemoteMinSize = undefined;
|
|
942
945
|
this.remoteBuffer = [];
|
|
943
946
|
this.remoteTimer = null;
|
|
944
947
|
}
|
|
@@ -949,6 +952,7 @@ class ____AnaLogger
|
|
|
949
952
|
}
|
|
950
953
|
|
|
951
954
|
setOptions({
|
|
955
|
+
timeLenMax = undefined,
|
|
952
956
|
contextLenMax = 10,
|
|
953
957
|
idLenMax = 5,
|
|
954
958
|
lidLenMax = 6,
|
|
@@ -976,11 +980,14 @@ class ____AnaLogger
|
|
|
976
980
|
oneConsolePerContext = undefined,
|
|
977
981
|
silent = undefined,
|
|
978
982
|
enableDate = undefined,
|
|
983
|
+
enableMillisec = undefined,
|
|
979
984
|
logToLocalStorage = undefined,
|
|
980
985
|
logToLocalStorageMax = 50,
|
|
981
986
|
logToLocalStorageSize = 10000,
|
|
982
987
|
logToRemoteMaxEntries = undefined,
|
|
983
988
|
logToRemoteDebounce = undefined,
|
|
989
|
+
logToRemoteMaxSize = undefined,
|
|
990
|
+
logToRemoteMinSize = undefined,
|
|
984
991
|
/** Remote - all optional **/
|
|
985
992
|
protocol = undefined,
|
|
986
993
|
host = undefined,
|
|
@@ -996,6 +1003,9 @@ class ____AnaLogger
|
|
|
996
1003
|
this.options.messageLenMax = messageLenMax;
|
|
997
1004
|
this.options.symbolLenMax = symbolLenMax;
|
|
998
1005
|
|
|
1006
|
+
this.options.enableMillisec = enableMillisec;
|
|
1007
|
+
this.options.timeLenMax = timeLenMax;
|
|
1008
|
+
|
|
999
1009
|
this.options.logMaxSize = logMaxSize;
|
|
1000
1010
|
this.options.logMaxArchives = logMaxArchives;
|
|
1001
1011
|
this.options.logIndexArchive = logIndexArchive;
|
|
@@ -1007,10 +1017,23 @@ class ____AnaLogger
|
|
|
1007
1017
|
this.options.requiredLogLevel = requiredLogLevel;
|
|
1008
1018
|
this.options.enableTrace = enableTrace;
|
|
1009
1019
|
|
|
1020
|
+
this.options.enableMillisec = enableMillisec;
|
|
1021
|
+
if (this.options.enableMillisec)
|
|
1022
|
+
{
|
|
1023
|
+
this.options.timeLenMax += 4;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1010
1026
|
this.options.logToLocalStorageMax = logToLocalStorageMax;
|
|
1011
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;
|
|
1012
1033
|
this.options.logToRemoteMaxEntries = logToRemoteMaxEntries;
|
|
1013
1034
|
this.options.logToRemoteDebounce = logToRemoteDebounce;
|
|
1035
|
+
this.options.logToRemoteMaxSize = logToRemoteMaxSize;
|
|
1036
|
+
this.options.logToRemoteMinSize = logToRemoteMinSize;
|
|
1014
1037
|
|
|
1015
1038
|
if (loadHtmlToImage) {
|
|
1016
1039
|
const code = getHtmlToImage();
|
|
@@ -1068,6 +1091,19 @@ class ____AnaLogger
|
|
|
1068
1091
|
}
|
|
1069
1092
|
});
|
|
1070
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
|
+
|
|
1071
1107
|
if (this.options.logToRemote && !this.options.logToRemoteUrl)
|
|
1072
1108
|
{
|
|
1073
1109
|
this.options.logToRemoteUrl = this.convertToUrl({
|
|
@@ -1141,17 +1177,14 @@ class ____AnaLogger
|
|
|
1141
1177
|
/**
|
|
1142
1178
|
* Format inputs
|
|
1143
1179
|
* @see Override {@link setLogFormat}
|
|
1144
|
-
* @param contextName
|
|
1145
|
-
* @param id
|
|
1146
|
-
* @param message
|
|
1147
|
-
* @param lid
|
|
1148
|
-
* @param symbol
|
|
1149
1180
|
* @returns {string}
|
|
1181
|
+
* @param localContext
|
|
1150
1182
|
*/
|
|
1151
|
-
onBuildLog(
|
|
1183
|
+
onBuildLog(localContext = {})
|
|
1152
1184
|
{
|
|
1153
1185
|
try
|
|
1154
1186
|
{
|
|
1187
|
+
let {contextName, message = "", lid = "", symbol = ""} = localContext;
|
|
1155
1188
|
let strResult = "";
|
|
1156
1189
|
|
|
1157
1190
|
const strs = message.split(/\n/g);
|
|
@@ -1164,14 +1197,22 @@ class ____AnaLogger
|
|
|
1164
1197
|
const now = new Date();
|
|
1165
1198
|
let time = ("0" + now.getHours()).slice(-2) + ":" + ("0" + now.getMinutes()).slice(-2) + ":" + ("0" + now.getSeconds()).slice(-2);
|
|
1166
1199
|
|
|
1167
|
-
|
|
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)
|
|
1168
1208
|
{
|
|
1169
1209
|
let date = now.getFullYear().toString().slice(-2) + "-" + (now.getMonth() + 1).toString().padStart(2, "0") + "-" + now.getDate().toString().padStart(2, "0");
|
|
1170
1210
|
time = date + " " + time;
|
|
1171
1211
|
}
|
|
1172
1212
|
|
|
1173
1213
|
// Display content in columns
|
|
1174
|
-
|
|
1214
|
+
const timeLenMax = localContext.hasOwnProperty("timeLenMax") ? localContext.timeLenMax : this.options.timeLenMax;
|
|
1215
|
+
time = this.truncateMessage(time, {fit: timeLenMax});
|
|
1175
1216
|
|
|
1176
1217
|
if (i > 0)
|
|
1177
1218
|
{
|
|
@@ -1184,7 +1225,8 @@ class ____AnaLogger
|
|
|
1184
1225
|
});
|
|
1185
1226
|
lid = this.truncateMessage(lid, {fit: this.options.lidLenMax});
|
|
1186
1227
|
|
|
1187
|
-
|
|
1228
|
+
const messageLenMax = localContext.hasOwnProperty("messageLenMax") ? localContext.messageLenMax : this.options.messageLenMax;
|
|
1229
|
+
if (messageLenMax !== undefined)
|
|
1188
1230
|
{
|
|
1189
1231
|
message0 = this.truncateMessage(message0, {fit: this.options.messageLenMax});
|
|
1190
1232
|
}
|
|
@@ -2006,20 +2048,31 @@ class ____AnaLogger
|
|
|
2006
2048
|
{
|
|
2007
2049
|
try
|
|
2008
2050
|
{
|
|
2009
|
-
if (this.options.logToRemoteMaxEntries === undefined && this.options.logToRemoteDebounce === undefined)
|
|
2051
|
+
if (this.options.logToRemoteMaxEntries === undefined && this.options.logToRemoteDebounce === undefined && this.options.logToRemoteMaxSize === undefined)
|
|
2010
2052
|
{
|
|
2011
2053
|
this.performRemotePost([...data]);
|
|
2012
2054
|
return;
|
|
2013
2055
|
}
|
|
2014
2056
|
|
|
2015
|
-
if (this.remoteBuffer)
|
|
2057
|
+
if (Array.isArray(this.remoteBuffer))
|
|
2016
2058
|
{
|
|
2017
2059
|
this.remoteBuffer.push([...data]);
|
|
2060
|
+
|
|
2018
2061
|
if (this.options.logToRemoteMaxEntries !== undefined && this.remoteBuffer.length >= this.options.logToRemoteMaxEntries)
|
|
2019
2062
|
{
|
|
2020
2063
|
this.flushRemoteLogs();
|
|
2021
2064
|
return;
|
|
2022
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
|
+
}
|
|
2023
2076
|
}
|
|
2024
2077
|
|
|
2025
2078
|
if (this.options.logToRemoteDebounce !== undefined && !this.remoteTimer)
|
|
@@ -2039,15 +2092,32 @@ class ____AnaLogger
|
|
|
2039
2092
|
|
|
2040
2093
|
flushRemoteLogs()
|
|
2041
2094
|
{
|
|
2042
|
-
if (this.
|
|
2095
|
+
if (this.remoteBuffer.length === 0)
|
|
2043
2096
|
{
|
|
2044
|
-
|
|
2045
|
-
this.remoteTimer = null;
|
|
2097
|
+
return;
|
|
2046
2098
|
}
|
|
2047
2099
|
|
|
2048
|
-
if (this.
|
|
2100
|
+
if (this.options.logToRemoteMinSize !== undefined)
|
|
2049
2101
|
{
|
|
2050
|
-
|
|
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;
|
|
2051
2121
|
}
|
|
2052
2122
|
|
|
2053
2123
|
const dataToFlush = [...this.remoteBuffer];
|