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/src/ana-logger.cjs
CHANGED
|
@@ -638,6 +638,9 @@ class ____AnaLogger
|
|
|
638
638
|
hideHookMessage: false
|
|
639
639
|
};
|
|
640
640
|
|
|
641
|
+
remoteBuffer = [];
|
|
642
|
+
remoteTimer = null;
|
|
643
|
+
|
|
641
644
|
static Console = null;
|
|
642
645
|
|
|
643
646
|
#overridenMap = {
|
|
@@ -687,6 +690,9 @@ class ____AnaLogger
|
|
|
687
690
|
this.errorTargetHandler = this.onError.bind(this);
|
|
688
691
|
this.errorUserTargetHandler = this.onErrorForUserTarget.bind(this);
|
|
689
692
|
|
|
693
|
+
this.remoteBuffer = [];
|
|
694
|
+
this.remoteTimer = null;
|
|
695
|
+
|
|
690
696
|
this.setOptions(this.options);
|
|
691
697
|
|
|
692
698
|
if (!____AnaLogger.Console) {
|
|
@@ -924,13 +930,17 @@ class ____AnaLogger
|
|
|
924
930
|
this.options.pathname = undefined;
|
|
925
931
|
this.options.binarypathname = undefined;
|
|
926
932
|
this.options.enableDate = undefined;
|
|
933
|
+
this.options.enableMillisec = undefined;
|
|
927
934
|
this.options.logToLocalStorage = undefined;
|
|
928
935
|
this.options.logToLocalStorageMax = 50;
|
|
929
936
|
this.options.logToLocalStorageSize = 10000;
|
|
930
937
|
this.options.logToRemoteMaxEntries = undefined;
|
|
931
938
|
this.options.logToRemoteDebounce = undefined;
|
|
939
|
+
this.options.logToRemoteMaxSize = undefined;
|
|
940
|
+
this.options.logToRemoteMinSize = undefined;
|
|
932
941
|
this.remoteBuffer = [];
|
|
933
942
|
this.remoteTimer = null;
|
|
943
|
+
this.remoteWaitCount = 0;
|
|
934
944
|
}
|
|
935
945
|
|
|
936
946
|
resetOptions()
|
|
@@ -939,6 +949,7 @@ class ____AnaLogger
|
|
|
939
949
|
}
|
|
940
950
|
|
|
941
951
|
setOptions({
|
|
952
|
+
timeLenMax = undefined,
|
|
942
953
|
contextLenMax = 10,
|
|
943
954
|
idLenMax = 5,
|
|
944
955
|
lidLenMax = 6,
|
|
@@ -966,11 +977,14 @@ class ____AnaLogger
|
|
|
966
977
|
oneConsolePerContext = undefined,
|
|
967
978
|
silent = undefined,
|
|
968
979
|
enableDate = undefined,
|
|
980
|
+
enableMillisec = undefined,
|
|
969
981
|
logToLocalStorage = undefined,
|
|
970
982
|
logToLocalStorageMax = 50,
|
|
971
983
|
logToLocalStorageSize = 10000,
|
|
972
984
|
logToRemoteMaxEntries = undefined,
|
|
973
985
|
logToRemoteDebounce = undefined,
|
|
986
|
+
logToRemoteMaxSize = undefined,
|
|
987
|
+
logToRemoteMinSize = undefined,
|
|
974
988
|
/** Remote - all optional **/
|
|
975
989
|
protocol = undefined,
|
|
976
990
|
host = undefined,
|
|
@@ -986,6 +1000,9 @@ class ____AnaLogger
|
|
|
986
1000
|
this.options.messageLenMax = messageLenMax;
|
|
987
1001
|
this.options.symbolLenMax = symbolLenMax;
|
|
988
1002
|
|
|
1003
|
+
this.options.enableMillisec = enableMillisec;
|
|
1004
|
+
this.options.timeLenMax = timeLenMax;
|
|
1005
|
+
|
|
989
1006
|
this.options.logMaxSize = logMaxSize;
|
|
990
1007
|
this.options.logMaxArchives = logMaxArchives;
|
|
991
1008
|
this.options.logIndexArchive = logIndexArchive;
|
|
@@ -997,10 +1014,23 @@ class ____AnaLogger
|
|
|
997
1014
|
this.options.requiredLogLevel = requiredLogLevel;
|
|
998
1015
|
this.options.enableTrace = enableTrace;
|
|
999
1016
|
|
|
1017
|
+
this.options.enableMillisec = enableMillisec;
|
|
1018
|
+
if (this.options.enableMillisec)
|
|
1019
|
+
{
|
|
1020
|
+
this.options.timeLenMax += 4;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1000
1023
|
this.options.logToLocalStorageMax = logToLocalStorageMax;
|
|
1001
1024
|
this.options.logToLocalStorageSize = logToLocalStorageSize;
|
|
1025
|
+
|
|
1026
|
+
// Remote logging options
|
|
1027
|
+
this.options.logToRemote = logToRemote;
|
|
1028
|
+
this.options.logToRemoteUrl = logToRemoteUrl;
|
|
1029
|
+
this.options.logToRemoteBinaryUrl = logToRemoteBinaryUrl;
|
|
1002
1030
|
this.options.logToRemoteMaxEntries = logToRemoteMaxEntries;
|
|
1003
1031
|
this.options.logToRemoteDebounce = logToRemoteDebounce;
|
|
1032
|
+
this.options.logToRemoteMaxSize = logToRemoteMaxSize;
|
|
1033
|
+
this.options.logToRemoteMinSize = logToRemoteMinSize;
|
|
1004
1034
|
|
|
1005
1035
|
if (loadHtmlToImage) {
|
|
1006
1036
|
const code = getHtmlToImage();
|
|
@@ -1058,6 +1088,19 @@ class ____AnaLogger
|
|
|
1058
1088
|
}
|
|
1059
1089
|
});
|
|
1060
1090
|
|
|
1091
|
+
if (this.options.enableDate && this.options.timeLenMax === undefined) {
|
|
1092
|
+
this.options.timeLenMax = 17;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
if (this.options.timeLenMax === undefined) {
|
|
1096
|
+
if (this.options.enableDate) {
|
|
1097
|
+
this.options.timeLenMax = 17;
|
|
1098
|
+
}
|
|
1099
|
+
else {
|
|
1100
|
+
this.options.timeLenMax = 8;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1061
1104
|
if (this.options.logToRemote && !this.options.logToRemoteUrl)
|
|
1062
1105
|
{
|
|
1063
1106
|
this.options.logToRemoteUrl = this.convertToUrl({
|
|
@@ -1136,17 +1179,14 @@ class ____AnaLogger
|
|
|
1136
1179
|
/**
|
|
1137
1180
|
* Format inputs
|
|
1138
1181
|
* @see Override {@link setLogFormat}
|
|
1139
|
-
* @param contextName
|
|
1140
|
-
* @param id
|
|
1141
|
-
* @param message
|
|
1142
|
-
* @param lid
|
|
1143
|
-
* @param symbol
|
|
1144
1182
|
* @returns {string}
|
|
1183
|
+
* @param localContext
|
|
1145
1184
|
*/
|
|
1146
|
-
onBuildLog(
|
|
1185
|
+
onBuildLog(localContext = {})
|
|
1147
1186
|
{
|
|
1148
1187
|
try
|
|
1149
1188
|
{
|
|
1189
|
+
let {contextName, message = "", lid = "", symbol = ""} = localContext;
|
|
1150
1190
|
let strResult = "";
|
|
1151
1191
|
|
|
1152
1192
|
const strs = message.split(/\n/g);
|
|
@@ -1159,14 +1199,22 @@ class ____AnaLogger
|
|
|
1159
1199
|
const now = new Date();
|
|
1160
1200
|
let time = ("0" + now.getHours()).slice(-2) + ":" + ("0" + now.getMinutes()).slice(-2) + ":" + ("0" + now.getSeconds()).slice(-2);
|
|
1161
1201
|
|
|
1162
|
-
|
|
1202
|
+
const enableMillisec = localContext.hasOwnProperty("enableMillisec") ? localContext.enableMillisec : this.options.enableMillisec;
|
|
1203
|
+
if (enableMillisec)
|
|
1204
|
+
{
|
|
1205
|
+
time += "," + ("00" + now.getMilliseconds()).slice(-3);
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
const enableDate = localContext.hasOwnProperty("enableDate") ? localContext.enableDate : this.options.enableDate;
|
|
1209
|
+
if (enableDate)
|
|
1163
1210
|
{
|
|
1164
1211
|
let date = now.getFullYear().toString().slice(-2) + "-" + (now.getMonth() + 1).toString().padStart(2, "0") + "-" + now.getDate().toString().padStart(2, "0");
|
|
1165
1212
|
time = date + " " + time;
|
|
1166
1213
|
}
|
|
1167
1214
|
|
|
1168
1215
|
// Display content in columns
|
|
1169
|
-
|
|
1216
|
+
const timeLenMax = localContext.hasOwnProperty("timeLenMax") ? localContext.timeLenMax : this.options.timeLenMax;
|
|
1217
|
+
time = this.truncateMessage(time, {fit: timeLenMax});
|
|
1170
1218
|
|
|
1171
1219
|
if (i > 0)
|
|
1172
1220
|
{
|
|
@@ -1179,7 +1227,8 @@ class ____AnaLogger
|
|
|
1179
1227
|
});
|
|
1180
1228
|
lid = this.truncateMessage(lid, {fit: this.options.lidLenMax});
|
|
1181
1229
|
|
|
1182
|
-
|
|
1230
|
+
const messageLenMax = localContext.hasOwnProperty("messageLenMax") ? localContext.messageLenMax : this.options.messageLenMax;
|
|
1231
|
+
if (messageLenMax !== undefined)
|
|
1183
1232
|
{
|
|
1184
1233
|
message0 = this.truncateMessage(message0, {fit: this.options.messageLenMax});
|
|
1185
1234
|
}
|
|
@@ -2001,18 +2050,31 @@ class ____AnaLogger
|
|
|
2001
2050
|
{
|
|
2002
2051
|
try
|
|
2003
2052
|
{
|
|
2004
|
-
if (this.options.logToRemoteMaxEntries === undefined && this.options.logToRemoteDebounce === undefined)
|
|
2053
|
+
if (this.options.logToRemoteMaxEntries === undefined && this.options.logToRemoteDebounce === undefined && this.options.logToRemoteMaxSize === undefined)
|
|
2005
2054
|
{
|
|
2006
2055
|
this.performRemotePost([...data]);
|
|
2007
2056
|
return;
|
|
2008
2057
|
}
|
|
2009
2058
|
|
|
2010
|
-
this.remoteBuffer
|
|
2011
|
-
|
|
2012
|
-
if (this.options.logToRemoteMaxEntries !== undefined && this.remoteBuffer.length >= this.options.logToRemoteMaxEntries)
|
|
2059
|
+
if (Array.isArray(this.remoteBuffer))
|
|
2013
2060
|
{
|
|
2014
|
-
this.
|
|
2015
|
-
|
|
2061
|
+
this.remoteBuffer.push([...data]);
|
|
2062
|
+
|
|
2063
|
+
if (this.options.logToRemoteMaxEntries !== undefined && this.remoteBuffer.length >= this.options.logToRemoteMaxEntries)
|
|
2064
|
+
{
|
|
2065
|
+
this.flushRemoteLogs(true);
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
if (this.options.logToRemoteMaxSize !== undefined)
|
|
2070
|
+
{
|
|
2071
|
+
const currentSize = JSON.stringify(this.remoteBuffer).length;
|
|
2072
|
+
if (currentSize >= this.options.logToRemoteMaxSize)
|
|
2073
|
+
{
|
|
2074
|
+
this.flushRemoteLogs(true);
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2016
2078
|
}
|
|
2017
2079
|
|
|
2018
2080
|
if (this.options.logToRemoteDebounce !== undefined && !this.remoteTimer)
|
|
@@ -2030,19 +2092,48 @@ class ____AnaLogger
|
|
|
2030
2092
|
}
|
|
2031
2093
|
}
|
|
2032
2094
|
|
|
2033
|
-
flushRemoteLogs()
|
|
2095
|
+
flushRemoteLogs(force = false)
|
|
2034
2096
|
{
|
|
2035
|
-
if (this.
|
|
2097
|
+
if (this.remoteBuffer.length === 0)
|
|
2036
2098
|
{
|
|
2037
|
-
|
|
2038
|
-
this.remoteTimer = null;
|
|
2099
|
+
return;
|
|
2039
2100
|
}
|
|
2040
2101
|
|
|
2041
|
-
if (this.
|
|
2102
|
+
if (!force && this.options.logToRemoteMinSize !== undefined)
|
|
2042
2103
|
{
|
|
2043
|
-
|
|
2104
|
+
const currentSize = JSON.stringify(this.remoteBuffer).length;
|
|
2105
|
+
if (currentSize < this.options.logToRemoteMinSize)
|
|
2106
|
+
{
|
|
2107
|
+
// If we haven't reached min size, increment wait count
|
|
2108
|
+
this.remoteWaitCount = (this.remoteWaitCount || 0) + 1;
|
|
2109
|
+
|
|
2110
|
+
// If we've waited long enough (e.g. 1 consecutive skip), flush anyway
|
|
2111
|
+
if (this.remoteWaitCount < 2)
|
|
2112
|
+
{
|
|
2113
|
+
// If we haven't reached min size, and there's no timer, start one if debounce is set
|
|
2114
|
+
if (this.options.logToRemoteDebounce !== undefined)
|
|
2115
|
+
{
|
|
2116
|
+
if (this.remoteTimer)
|
|
2117
|
+
{
|
|
2118
|
+
clearTimeout(this.remoteTimer);
|
|
2119
|
+
}
|
|
2120
|
+
this.remoteTimer = setTimeout(() =>
|
|
2121
|
+
{
|
|
2122
|
+
this.flushRemoteLogs();
|
|
2123
|
+
}, this.options.logToRemoteDebounce);
|
|
2124
|
+
}
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
if (this.remoteTimer)
|
|
2131
|
+
{
|
|
2132
|
+
clearTimeout(this.remoteTimer);
|
|
2133
|
+
this.remoteTimer = null;
|
|
2044
2134
|
}
|
|
2045
2135
|
|
|
2136
|
+
this.remoteWaitCount = 0;
|
|
2046
2137
|
const dataToFlush = [...this.remoteBuffer];
|
|
2047
2138
|
this.remoteBuffer = [];
|
|
2048
2139
|
|
package/src/ana-logger.d.cts
CHANGED
|
@@ -99,7 +99,7 @@ declare class ____AnaLogger {
|
|
|
99
99
|
isBrowser(): boolean;
|
|
100
100
|
resetLogger(): void;
|
|
101
101
|
resetOptions(): void;
|
|
102
|
-
setOptions({ contextLenMax, idLenMax, lidLenMax, symbolLenMax, messageLenMax, hideLog, hideError, hideHookMessage, hidePassingTests, logToDom, logToFile, logMaxSize, logMaxArchives, logIndexArchive, addArchiveTimestamp, addArchiveIndex, compressArchives, compressionLevel, logToRemote, logToRemoteUrl, logToRemoteBinaryUrl, loopback, requiredLogLevel, oneConsolePerContext, silent, enableDate, protocol, host, port, pathname, binarypathname }?: any): void;
|
|
102
|
+
setOptions({ contextLenMax, idLenMax, lidLenMax, symbolLenMax, messageLenMax, hideLog, hideError, hideHookMessage, hidePassingTests, logToDom, logToFile, logMaxSize, logMaxArchives, logIndexArchive, addArchiveTimestamp, addArchiveIndex, compressArchives, compressionLevel, logToRemote, logToRemoteUrl, logToRemoteBinaryUrl, loopback, requiredLogLevel, oneConsolePerContext, silent, enableDate, enableMillisec, protocol, host, port, pathname, binarypathname }?: any): void;
|
|
103
103
|
EOL: string;
|
|
104
104
|
getOptions(): {
|
|
105
105
|
hideHookMessage: boolean;
|