analogger 1.20.4 → 1.21.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/CHANGELOG.md +3 -1
- package/README.md +98 -0
- package/browser/src/ana-logger.mjs +115 -53
- package/browser/src/html-to-image-plugin.mjs +12 -6
- package/dist/analogger-browser.min.mjs +3 -3
- package/esm/src/ana-logger.mjs +115 -53
- package/package.json +1 -1
- package/src/ana-logger.cjs +115 -53
- package/src/html-to-image-plugin.cjs +12 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
# [1.21.0](https://github.com/thimpat/analogger/compare/v1.20.4...v1.21.0) (2022-09-10)
|
|
2
2
|
|
|
3
|
+
## [1.20.4](https://github.com/thimpat/analogger/compare/v1.20.3...v1.20.4) (2022-09-07)
|
|
4
|
+
|
|
3
5
|
## [1.20.3](https://github.com/thimpat/analogger/compare/v1.20.2...v1.20.3) (2022-09-07)
|
|
4
6
|
|
|
5
7
|
## [1.20.2](https://github.com/thimpat/analogger/compare/v1.20.1...v1.20.2) (2022-09-07)
|
package/README.md
CHANGED
|
@@ -375,6 +375,34 @@ anaLogger.setOptions({logToRemote: "http://your.server.com/data"});
|
|
|
375
375
|
|
|
376
376
|
---
|
|
377
377
|
|
|
378
|
+
### attachConsole();
|
|
379
|
+
|
|
380
|
+
Allows to use the methods defined in the anaLogger instance directly from the console
|
|
381
|
+
|
|
382
|
+
```javascript
|
|
383
|
+
|
|
384
|
+
// Attach methods like keepLogHistory(), hasSeenLid(), etc. to the console
|
|
385
|
+
anaLogger.attachConsole();
|
|
386
|
+
|
|
387
|
+
console.keepLogHistory();
|
|
388
|
+
|
|
389
|
+
[1, -1, 3, -1, -1].forEach((n) =>
|
|
390
|
+
{
|
|
391
|
+
if (n === -1)
|
|
392
|
+
{
|
|
393
|
+
if (!console.hasSeenLid(3000))
|
|
394
|
+
{
|
|
395
|
+
console.log({lid: 3000}, `-1 is not allowed`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
<br/>
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
378
406
|
### overrideConsole()
|
|
379
407
|
|
|
380
408
|
```javascript
|
|
@@ -623,6 +651,76 @@ anaLogger.assert((a, b)=> a === b, true, 2, 2)
|
|
|
623
651
|
---
|
|
624
652
|
|
|
625
653
|
|
|
654
|
+
### setErrorHandlerForUserTarget()
|
|
655
|
+
|
|
656
|
+
Tells whether a log has already been displayed. keepLogHistory must be activated
|
|
657
|
+
|
|
658
|
+
```javascript
|
|
659
|
+
anaLogger.keepLogHistory()
|
|
660
|
+
|
|
661
|
+
anaLogger.log({lid: 1234}, `My name is log`)
|
|
662
|
+
anaLogger.hasSeenLid(1234) // true
|
|
663
|
+
anaLogger.hasSeenLid(1000) // false
|
|
664
|
+
|
|
665
|
+
// Optional
|
|
666
|
+
anaLogger.releaseLogHistory()
|
|
667
|
+
```
|
|
668
|
+
<br/>
|
|
669
|
+
---
|
|
670
|
+
|
|
671
|
+
### isBrowser()()
|
|
672
|
+
|
|
673
|
+
Tells whether the console runs from the browser
|
|
674
|
+
|
|
675
|
+
```javascript
|
|
676
|
+
anaLogger.isBrowser()
|
|
677
|
+
```
|
|
678
|
+
<br/>
|
|
679
|
+
|
|
680
|
+
---
|
|
681
|
+
### keepLogHistory()
|
|
682
|
+
|
|
683
|
+
Keeps log entries in memory
|
|
684
|
+
|
|
685
|
+
```javascript
|
|
686
|
+
anaLogger.keepLogHistory()
|
|
687
|
+
```
|
|
688
|
+
<br/>
|
|
689
|
+
---
|
|
690
|
+
|
|
691
|
+
### releaseLogHistory()
|
|
692
|
+
|
|
693
|
+
Tells the system to no longer keep log entries in memory
|
|
694
|
+
|
|
695
|
+
```javascript
|
|
696
|
+
anaLogger.releaseLogHistory()
|
|
697
|
+
```
|
|
698
|
+
<br/>
|
|
699
|
+
---
|
|
700
|
+
|
|
701
|
+
### resetLogHistory()
|
|
702
|
+
|
|
703
|
+
Delete memorized log entries
|
|
704
|
+
|
|
705
|
+
```javascript
|
|
706
|
+
anaLogger.resetLogHistory()
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
<br/>
|
|
710
|
+
---
|
|
711
|
+
|
|
712
|
+
### getLogHistory()
|
|
713
|
+
|
|
714
|
+
Returns log entries
|
|
715
|
+
|
|
716
|
+
```javascript
|
|
717
|
+
anaLogger.getLogHistory()
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
<br/>
|
|
721
|
+
---
|
|
722
|
+
|
|
723
|
+
|
|
626
724
|
### setErrorHandlerForUserTarget()
|
|
627
725
|
|
|
628
726
|
When an error is detected and should be seen by your app consumers explicitly (for instance, you want to display a
|
|
@@ -200,6 +200,21 @@ function isNode()
|
|
|
200
200
|
return currentSystem === SYSTEM.NODE;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
+
const COMMON_METHODS = [
|
|
204
|
+
"keepLogHistory",
|
|
205
|
+
"getLogHistory",
|
|
206
|
+
"table",
|
|
207
|
+
"buildTable",
|
|
208
|
+
"truncateMessage",
|
|
209
|
+
"truncateMessage",
|
|
210
|
+
"rawLog",
|
|
211
|
+
"rawInfo",
|
|
212
|
+
"rawWarn",
|
|
213
|
+
"rawError",
|
|
214
|
+
"hasSeenLid"
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
|
|
203
218
|
/**
|
|
204
219
|
* @module ____AnaLogger
|
|
205
220
|
* @class ____AnaLogger
|
|
@@ -279,24 +294,6 @@ class ____AnaLogger
|
|
|
279
294
|
this.rawWarn = this.#realConsoleWarn;
|
|
280
295
|
this.rawError = this.#realConsoleError;
|
|
281
296
|
|
|
282
|
-
console.rawLog = this.#realConsoleLog;
|
|
283
|
-
console.raw = this.#realConsoleLog;
|
|
284
|
-
|
|
285
|
-
console.rawInfo = this.#realConsoleInfo;
|
|
286
|
-
console.rawWarn = this.#realConsoleWarn;
|
|
287
|
-
console.rawError = this.#realConsoleError;
|
|
288
|
-
|
|
289
|
-
console.keepLogHistory = this.keepLogHistory;
|
|
290
|
-
console.getLogHistory = this.getLogHistory;
|
|
291
|
-
|
|
292
|
-
console.table = this.table;
|
|
293
|
-
console.buildTable = this.buildTable;
|
|
294
|
-
console.truncateMessage = this.truncateMessage;
|
|
295
|
-
console.rawLog = this.rawLog;
|
|
296
|
-
console.rawInfo = this.rawInfo;
|
|
297
|
-
console.rawWarn = this.rawWarn;
|
|
298
|
-
console.rawError = this.rawError;
|
|
299
|
-
|
|
300
297
|
this.ALIGN = ____AnaLogger.ALIGN;
|
|
301
298
|
this.ENVIRONMENT_TYPE = ____AnaLogger.ENVIRONMENT_TYPE;
|
|
302
299
|
|
|
@@ -330,22 +327,59 @@ class ____AnaLogger
|
|
|
330
327
|
this.logHistory = [];
|
|
331
328
|
}
|
|
332
329
|
|
|
330
|
+
addToLogHistory(obj)
|
|
331
|
+
{
|
|
332
|
+
obj = obj || {};
|
|
333
|
+
this.logHistory.push(Object.assign({}, obj));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Returns log entries
|
|
338
|
+
* @note This method should return the list of objects rather than
|
|
339
|
+
* the array of text
|
|
340
|
+
* @param join
|
|
341
|
+
* @param symbol
|
|
342
|
+
* @returns {string|*[]}
|
|
343
|
+
*/
|
|
333
344
|
getLogHistory(join = true, symbol = EOL)
|
|
334
345
|
{
|
|
335
|
-
const historyLog = this.logHistory;
|
|
336
|
-
|
|
346
|
+
const historyLog = this.logHistory || [];
|
|
347
|
+
const history = [];
|
|
348
|
+
historyLog.forEach((logEntry) =>
|
|
337
349
|
{
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
350
|
+
const {text} = logEntry;
|
|
351
|
+
history.push(text);
|
|
352
|
+
});
|
|
353
|
+
|
|
342
354
|
if (!join)
|
|
343
355
|
{
|
|
344
356
|
return history;
|
|
345
357
|
}
|
|
358
|
+
|
|
346
359
|
return history.join(symbol);
|
|
347
360
|
}
|
|
348
361
|
|
|
362
|
+
getRawLogHistory()
|
|
363
|
+
{
|
|
364
|
+
return this.logHistory || [];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
hasSeenLid(lid)
|
|
368
|
+
{
|
|
369
|
+
this.logHistory = this.logHistory || [];
|
|
370
|
+
for (let i = 0; i < this.logHistory.length; ++i)
|
|
371
|
+
{
|
|
372
|
+
const log = this.logHistory[i] || {};
|
|
373
|
+
const context = log.context || {};
|
|
374
|
+
if (lid === context.lid)
|
|
375
|
+
{
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
|
|
349
383
|
forceEnvironment(system)
|
|
350
384
|
{
|
|
351
385
|
this.forcedSystem = system;
|
|
@@ -546,7 +580,7 @@ class ____AnaLogger
|
|
|
546
580
|
* @param onCompleteSeparators
|
|
547
581
|
* @param onCompleteLines
|
|
548
582
|
*/
|
|
549
|
-
buildTable(objList, {
|
|
583
|
+
#buildTable(objList, {
|
|
550
584
|
ellipsis = "...",
|
|
551
585
|
ColumnMinChars = 6,
|
|
552
586
|
columnMaxChars = 0,
|
|
@@ -1556,13 +1590,13 @@ class ____AnaLogger
|
|
|
1556
1590
|
let proceedFurther = true;
|
|
1557
1591
|
for (let keyName in context)
|
|
1558
1592
|
{
|
|
1559
|
-
const
|
|
1593
|
+
const pluginOptions = context[keyName];
|
|
1560
1594
|
|
|
1561
1595
|
/**
|
|
1562
1596
|
* The key has been passed in the context, but has a falsy value,
|
|
1563
1597
|
* so let's ignore it
|
|
1564
1598
|
*/
|
|
1565
|
-
if (!
|
|
1599
|
+
if (!pluginOptions)
|
|
1566
1600
|
{
|
|
1567
1601
|
continue;
|
|
1568
1602
|
}
|
|
@@ -1598,18 +1632,18 @@ class ____AnaLogger
|
|
|
1598
1632
|
continue;
|
|
1599
1633
|
}
|
|
1600
1634
|
|
|
1601
|
-
/**
|
|
1602
|
-
* If the key given in the context was a function, invoke that function
|
|
1603
|
-
*/
|
|
1604
|
-
if (typeof pluginArgs === "function")
|
|
1605
|
-
{
|
|
1606
|
-
context = pluginArgs;
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
1635
|
/**
|
|
1610
1636
|
* Invoke the plugin
|
|
1611
1637
|
*/
|
|
1612
|
-
let res = callback.call(this, context, {
|
|
1638
|
+
let res = callback.call(this, context, {
|
|
1639
|
+
message,
|
|
1640
|
+
text,
|
|
1641
|
+
args,
|
|
1642
|
+
logCounter,
|
|
1643
|
+
methodName,
|
|
1644
|
+
type,
|
|
1645
|
+
pluginOptions
|
|
1646
|
+
});
|
|
1613
1647
|
|
|
1614
1648
|
// If the plugin returns exactly false, the log entry will be ignored by anaLogger
|
|
1615
1649
|
if (res === false)
|
|
@@ -1683,6 +1717,11 @@ class ____AnaLogger
|
|
|
1683
1717
|
let text = "";
|
|
1684
1718
|
text = this.format({...context, message});
|
|
1685
1719
|
|
|
1720
|
+
if (this.keepLog)
|
|
1721
|
+
{
|
|
1722
|
+
this.addToLogHistory({context, message, text});
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1686
1725
|
++this.logCounter;
|
|
1687
1726
|
|
|
1688
1727
|
let proceedFurther;
|
|
@@ -1737,11 +1776,6 @@ class ____AnaLogger
|
|
|
1737
1776
|
}
|
|
1738
1777
|
}
|
|
1739
1778
|
|
|
1740
|
-
if (this.keepLog)
|
|
1741
|
-
{
|
|
1742
|
-
this.logHistory.push(output);
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
1779
|
if (this.options.hideLog)
|
|
1746
1780
|
{
|
|
1747
1781
|
return;
|
|
@@ -1906,32 +1940,60 @@ class ____AnaLogger
|
|
|
1906
1940
|
console.error = this.onDisplayError.bind(this);
|
|
1907
1941
|
}
|
|
1908
1942
|
|
|
1909
|
-
|
|
1943
|
+
attachConsole()
|
|
1910
1944
|
{
|
|
1911
|
-
|
|
1945
|
+
try
|
|
1912
1946
|
{
|
|
1913
|
-
this.#realConsoleLog
|
|
1914
|
-
|
|
1947
|
+
console.rawLog = this.#realConsoleLog;
|
|
1948
|
+
console.raw = this.#realConsoleLog;
|
|
1915
1949
|
|
|
1916
|
-
|
|
1950
|
+
console.rawInfo = this.#realConsoleInfo;
|
|
1951
|
+
console.rawWarn = this.#realConsoleWarn;
|
|
1952
|
+
console.rawError = this.#realConsoleError;
|
|
1953
|
+
|
|
1954
|
+
console.logHistory = this.logHistory;
|
|
1955
|
+
|
|
1956
|
+
console.logHistory = this.logHistory;
|
|
1957
|
+
COMMON_METHODS.forEach((name) =>
|
|
1958
|
+
{
|
|
1959
|
+
console[name] = function (...args)
|
|
1960
|
+
{
|
|
1961
|
+
this[name](...args);
|
|
1962
|
+
}.bind(this);
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
return true;
|
|
1966
|
+
}
|
|
1967
|
+
catch (e)
|
|
1917
1968
|
{
|
|
1918
|
-
console.
|
|
1969
|
+
console.error({lid: 4321}, e.message);
|
|
1919
1970
|
}
|
|
1920
1971
|
|
|
1921
|
-
|
|
1972
|
+
return false;
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
overrideConsole({log = true, info = true, warn = true, error = false} = {}, Console = null)
|
|
1976
|
+
{
|
|
1977
|
+
if (!this.options.hideHookMessage)
|
|
1922
1978
|
{
|
|
1923
|
-
|
|
1979
|
+
this.#realConsoleLog("AnaLogger: Hook placed on console.log");
|
|
1924
1980
|
}
|
|
1925
1981
|
|
|
1926
|
-
|
|
1982
|
+
[{log}, {info}, {warn}, ].forEach((methodObj)=>
|
|
1927
1983
|
{
|
|
1928
|
-
|
|
1929
|
-
|
|
1984
|
+
const methodName = Object.keys(methodObj)[0];
|
|
1985
|
+
if (methodObj[methodName])
|
|
1986
|
+
{
|
|
1987
|
+
console[methodName] = this.onDisplayLog.bind(this);
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1930
1990
|
|
|
1931
1991
|
if (error)
|
|
1932
1992
|
{
|
|
1933
1993
|
this.overrideError();
|
|
1934
1994
|
}
|
|
1995
|
+
|
|
1996
|
+
this.attachConsole();
|
|
1935
1997
|
}
|
|
1936
1998
|
|
|
1937
1999
|
removeOverrideError()
|
|
@@ -1980,7 +2042,7 @@ class ____AnaLogger
|
|
|
1980
2042
|
return this.#realConsoleTable(...args);
|
|
1981
2043
|
}
|
|
1982
2044
|
|
|
1983
|
-
return this
|
|
2045
|
+
return this.#buildTable(...args);
|
|
1984
2046
|
}
|
|
1985
2047
|
|
|
1986
2048
|
alert(...args)
|
|
@@ -25,11 +25,18 @@ export const PLUGIN_NAME = "takeScreenshot";
|
|
|
25
25
|
* @param text
|
|
26
26
|
* @param methodName
|
|
27
27
|
* @param type
|
|
28
|
+
* @example
|
|
29
|
+
* anaLogger.log({lid: 1234, takeScreenshot: {
|
|
30
|
+
* divSource: document.body,n
|
|
31
|
+
* onScreenshot: () => {},
|
|
32
|
+
* onResponse: () => {},
|
|
33
|
+
* filter : {width: 500,}
|
|
34
|
+
* }}, "Take a screenshot 500px wide")
|
|
28
35
|
* @returns {boolean}
|
|
29
36
|
*/
|
|
30
37
|
const takeScreenshot = (context,
|
|
31
38
|
{
|
|
32
|
-
|
|
39
|
+
pluginOptions = {},
|
|
33
40
|
divSource = document.body,
|
|
34
41
|
args = null,
|
|
35
42
|
logCounter = -1,
|
|
@@ -41,14 +48,15 @@ const takeScreenshot = (context,
|
|
|
41
48
|
{
|
|
42
49
|
try
|
|
43
50
|
{
|
|
51
|
+
pluginOptions.options = pluginOptions.options || {};
|
|
44
52
|
htmlToImage
|
|
45
|
-
.toPng(divSource)
|
|
53
|
+
.toPng(divSource, pluginOptions.options)
|
|
46
54
|
.then(function (imageData)
|
|
47
55
|
{
|
|
48
56
|
// ------------------------------------
|
|
49
57
|
// Phase 1: We have the screenshot
|
|
50
58
|
// ------------------------------------
|
|
51
|
-
const onScreenshot =
|
|
59
|
+
const onScreenshot = pluginOptions ? pluginOptions.onScreenshot : null;
|
|
52
60
|
onScreenshot && onScreenshot({
|
|
53
61
|
imageData,
|
|
54
62
|
context,
|
|
@@ -65,7 +73,7 @@ const takeScreenshot = (context,
|
|
|
65
73
|
// ------------------------------------
|
|
66
74
|
// Phase 1: We have the screenshot url from the server
|
|
67
75
|
// ------------------------------------
|
|
68
|
-
const onResponse =
|
|
76
|
+
const onResponse = pluginOptions ? pluginOptions.onResponse : null;
|
|
69
77
|
// We transfer as much information as we can to the plugin
|
|
70
78
|
onResponse && onResponse({
|
|
71
79
|
imageData,
|
|
@@ -93,8 +101,6 @@ const takeScreenshot = (context,
|
|
|
93
101
|
console.error({lid: 4321}, e.message);
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
response = false;
|
|
97
|
-
return response;
|
|
98
104
|
};
|
|
99
105
|
|
|
100
106
|
anaLogger.addPlugin(PLUGIN_NAME, takeScreenshot);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,
|
|
3
|
-
`),o=[];for(let r=0;r<t.length;++r){let s=t[r];o.push(s)}return o}catch(t){console.rawError(t.message)}return e.message}onDisplayError(...e){try{let t=-1,o=null;for(let r=0;r<e.length;++r){let s=e[r];if(s instanceof Error&&s.stack){t=r,o=this.assistStask(s)||[];break}}if(!o){this.error(...e);return}for(let r=0;r<o.length;++r)e[t]=o[r],this.error(...e)}catch(t){console.rawError(t)}}setLogFormat(e){if(typeof e!="function")return console.error("Invalid parameter for setFormat. It is expecting a function or method."),!1;this.format=e.bind(this)}resetLogFormatter(){this.format=this.originalFormatFunction}setErrorHandler(e){this.errorTargetHandler=e.bind(this)}setErrorHandlerForUserTarget(e){this.errorUserTargetHandler=e.bind(this)}isContextValid(e){return typeof e=="object"&&!Array.isArray(e)&&e!==null?e.hasOwnProperty("contextName")&&e.hasOwnProperty("target"):!1}setDefaultContext(e){this.setContext(V.DEFAULT.contextName,e)}generateDefaultContext(){let e=a(this,S)[V.DEFAULT.contextName]||{};return e=Object.assign({},{lid:"",contextName:V.DEFAULT.contextName,target:q.ALL,symbol:"\u26A1",color:j[1],logLevel:E.LOG},e),e.name=e.contextName,e.id=this.logIndex++,e}generateNewContext(){let e=this.generateDefaultContext();return e.color=j[this.indexColor++%(j.length-3)+2],e.symbol="",e}generateErrorContext(){let e=this.generateDefaultContext();return e.contextName=V.ERROR.contextName,e.name=e.contextName,e.color=j[0],e.symbol="\u274C",e.error=!0,e.logLevel=E.ERROR,e}setContext(e,t={}){t.contextName=e,t.name=e,t=ce(this,ne,Me).call(this,t),a(this,S)[e]=t}getContext(e){return a(this,S)[e]}setContexts(e){Object.keys(e).forEach(o=>{let r=e[o]||{};this.setContext(o,r),e[o]=a(this,S)[o]})}getContexts(){return Object.freeze(a(this,S))}setTargets(e={}){let t={};if(Array.isArray(e))try{for(let o=0;o<e.length;++o){let r=e[o];if(typeof r=="string"||r instanceof String)t[r]=r;else if(typeof r=="object"){let s=null;for(let i in r){let l=r[i];if(i=i.trim(),!i){console.error("Invalid target");break}if(typeof l=="string"||l instanceof String){l=l.trim(),s=[i,l];break}if(typeof l=="number")break}s&&(t[s[0]]=s[1])}}}catch(o){console.error({lid:4321},o.message)}else t=e;ae(this,C,Object.assign({},t,{...q}))}addTargets(e){let t=a(this,C),o=Object.assign({},t,e);this.setTargets(o)}getTargets(){return Object.freeze(a(this,C))}setActiveTargets(e=null){if(e===null){this.activeTargets=[q.ALL];return}else if(typeof e=="string"||e instanceof String)e=e.split(",");else if(typeof e=="object"||typeof e=="function")return;for(let t=0;t<e.length;++t)e[t]=e[t].trim();this.activeTargets=e}getActiveTarget(){return this.activeTargets}setActiveTarget(e){this.activeTargets=[],this.setActiveTargets(e),this.activeTargets=[this.activeTargets[0]]}setLogLevel(e,t){a(this,M)[e]=t}getLogLevel(e){return a(this,M)[e]}setLogLevels(e){ae(this,M,e)}getLogLevels(){return Object.freeze(a(this,M))}isTargetAllowed(e){return!e||!this.activeTargets||!this.activeTargets.length||e===q.ALL||this.activeTargets.includes(q.ALL)?!0:this.activeTargets.includes(e)}setColumns(e,t,o){let r=0;for(let i in t){if(!["contextName","symbol","lid","text"].includes(i))continue;let l=t[i],c=document.createElement("span");c.classList.add("analogger-col",`analogger-col-${i}`,`analogger-col-${r}`),++r,c.textContent=l,e.append(c)}let s=document.createElement("span");s.classList.add("analogger-col","analogger-col-text",`analogger-col-${r}`),s.textContent=o,e.append(s);for(let i=1;i<=3;++i)s=document.createElement("span"),s.classList.add("analogger-col","analogger-col-extra",`analogger-extra-${i}`),e.append(s)}checkOnLoggingToDom(e,t){try{let o=e.onLoggingToDom;return typeof o!="function"?void 0:o.call(this,e,t)}catch{}}addLineToDom(e,t,{context:o,addType:r,message:s,text:i,args:l}){if(this.checkOnLoggingToDom(o,{message:s,text:i,args:l,logCounter:this.logCounter,$view:e,$line:t,addType:r})===!1)return;if(r===Z.BOTTOM?e.append(t):e.insertBefore(t,e.firstChild),this.removeDomOldEntries(e)){if(e.getElementsByClassName(ue).length)return;this.showRemovedNotification(o);return}this.scrollDivToBottom(e)}showRemovedNotification(e){e.contextName=_e,e.symbol="\u{1F5D1}",e.color="orange",e.className=ue,clearTimeout(this.timerAddLineToDomID),this.timerAddLineToDomID=setTimeout(()=>{this.timerAddLineToDomID=null,this.writeLogToDom(e,"",{addType:Z.TOP,message:"Oldest entries removed"})},500)}writeLogToDom(e,t,{addType:o=Z.BOTTOM,message:r="",args:s=null}={}){this.$containers=this.$containers||document.querySelectorAll(this.options.logToDom),t=r||t;for(let i=0;i<this.$containers.length;++i){let l=this.$containers[i],c=l.querySelector("."+ge);c||(c=document.createElement("div"),c.classList.add(ge),c.append(document.createElement("span")),c.append(document.createElement("span")),c.append(document.createElement("span")),l.append(c));let b=l.querySelector("."+pe);b||(b=document.createElement("div"),b.classList.add(pe),l.append(b));let g=l.querySelector("."+me);g||(g=document.createElement("div"),g.classList.add(me),g.append(document.createElement("span")),g.append(document.createElement("span")),g.append(document.createElement("span")),l.append(g));let f=document.createElement("div");f.classList.add(Re),e.className&&f.classList.add(e.className),f.style.color=e.color,this.setColumns(f,e,t,s),setTimeout(function(O,w,{addType:W,context:T,message:p,text:H,args:d}){this.addLineToDom(O,w,{addType:W,context:T,message:p,text:H,args:d})}.bind(this,b,f,{addType:o,context:e,message:r,text:t,args:s}),0)}}writeLogToFile(e){try{fs.appendFileSync(this.options.logToFilePath,e+this.EOL)}catch(t){console.rawError("LOG_TO_FILE_FAILURE: ",t.message)}}writeLogToRemote(...e){try{let t=this.generateLogToRemoteUrl(this.options.logToRemoteUrl);if(!t)return null;let o=[...e],r=JSON.stringify(o);fetch(t,{method:"post",body:r,headers:{"Content-Type":"application/json"}}).then(s=>s.json()).catch(()=>null)}catch(t){console.rawError("LOG_TO_REMOTE_FAILURE: ",t.message)}}uploadDataToRemote(e,t=null,o=null){try{if(!this.options.logToRemote)return;let r=this.generateLogToRemoteUrl(this.options.logToRemoteBinaryUrl,{pathname:v.binarypathname});if(!r)return null;let s=e;t&&(s=JSON.stringify({raw:e,context:t})),fetch(r,{method:"post",body:s}).then(i=>i.json()).then(i=>o&&o(i)).catch(i=>i)}catch(r){console.rawError("BINARY_TO_REMOTE_FAILURE: ",r.message)}}convertArgumentsToText(e){let t=[],o,r=e.length;for(let s=0;s<r;++s){let i,l=e[s];try{i=JSON.stringify(l)}catch{}if(!i)try{i=De(l)}catch{}t.push(i)}return o=t.join("\u2022"),o}writeToConsole(e,t){let o=[e];this.isBrowser()&&o.push(`color: ${t.color}`);let r=t.contextLevel||E.LOG;r>=E.ERROR?a(this,B).call(this,...o):r>=E.WARN?a(this,I).call(this,...o):r>=E.INFO?a(this,k).call(this,...o):r>=E.LOG?a(this,R).call(this,...o):r>=E.DEBUG&&a(this,oe).call(this,...o)}checkPlugins(e,{message:t,text:o,args:r,logCounter:s}){try{if(!Object.keys(L.pluginTable).length)return;let i=!0;for(let l in e){let c=e[l];if(!c)continue;let b=L.pluginTable[l];if(!b||typeof b!="object")continue;let{callback:g,methodName:f,type:O}=b;if(typeof g!="function")continue;typeof c=="function"&&(e=c),g.call(this,e,{message:t,text:o,args:r,logCounter:s,methodName:f,type:O,pluginArgs:c})===!1&&(i=!1)}return i}catch{}}checkOnLogging(e,t){try{let o=e.onLogging;return typeof o!="function"?void 0:o.call(this,e,t)}catch{}}processOutput(e={}){try{let t="";if(this.applySymbolByName(e),!this.isTargetAllowed(e.target)||e.logLevel===E.OFF||this.options.requiredLogLevel>e.logLevel)return;let o=Array.prototype.slice.call(arguments,1);t=this.convertArgumentsToText(o);let r="",s="";s=this.format({...e,message:t}),++this.logCounter;let i;if(i=this.checkOnLogging(e,{message:t,text:s,args:o,logCounter:this.logCounter}),i===!1||(i=this.checkPlugins(e,{message:t,text:s,args:o,logCounter:this.logCounter}),i===!1)||(this.options.logToRemote&&this.writeLogToRemote(e,...o),this.isBrowser()?(e.environnment=L.ENVIRONMENT_TYPE.BROWSER,this.options.logToDom&&this.writeLogToDom(e,s,{message:t,args:o}),r=`%c${s}`):(e.environnment=L.ENVIRONMENT_TYPE.NODE,r=Q.getTextFromColor(s,{fg:e.color,bg:e.bgColor,isBold:e.bold,isUnderline:e.underline,isReversed:e.reversed}),this.options.logToFile&&this.writeLogToFile(s)),this.keepLog&&this.logHistory.push(r),this.options.hideLog))return;this.writeToConsole(r,e),this.errorTargetHandler(e,o)}catch(t){console.rawError("AnaLogger:",t.message)}}isExtendedOptionsPassed(e){return typeof e!="object"?!1:e.hasOwnProperty("context")||e.hasOwnProperty("target")||e.hasOwnProperty("color")||e.hasOwnProperty("contextName")||e.hasOwnProperty("lid")}extractContextFromInput(e){return(typeof e=="string"||e instanceof String)&&e.toLowerCase().indexOf("lid:")!==0,e}listSymbols(){for(let e in te)console.rawLog(te[e]+` ${e} `)}applySymbolByName(e){try{e.symbol&&te[e.symbol]&&(e.symbol=te[e.symbol])}catch{}}convertToContext(e,t){e=e||t;let o=e;if(e.context&&typeof e.context=="object"){let r=Object.assign({},e);delete r.context,o=Object.assign({},e.context,r)}return o=Object.assign({},t,o),delete o.context,o}log(e,...t){if(e=this.extractContextFromInput(e),!this.isExtendedOptionsPassed(e)){let s=this.generateDefaultContext();this.processOutput.apply(this,[s,e,...t]);return}let o=this.generateDefaultContext(),r=this.convertToContext(e,o);this.processOutput.apply(this,[r,...t])}error(e,...t){if(this.options.hideError)return;if(e=this.extractContextFromInput(e),!this.isExtendedOptionsPassed(e)){let i=this.generateErrorContext();this.processOutput.apply(this,[i,e,...t]);return}let o=this.generateErrorContext(),r=this.convertToContext(e,o),s=Array.prototype.slice.call(arguments,1);this.log(r,...s)}overrideError(){this.options.hideHookMessage||a(this,R).call(this,"AnaLogger: Hook placed on console.error"),console.error=this.onDisplayError.bind(this)}overrideConsole({log:e=!0,info:t=!0,warn:o=!0,error:r=!1}={}){this.options.hideHookMessage||a(this,R).call(this,"AnaLogger: Hook placed on console.log"),e&&(console.log=this.onDisplayLog.bind(this)),t&&(console.info=this.onDisplayLog.bind(this)),o&&(console.warn=this.onDisplayLog.bind(this)),r&&this.overrideError()}removeOverrideError(){console.warn=a(this,B)}removeOverride({log:e=!0,info:t=!0,warn:o=!0,error:r=!1}={}){e&&(console.log=a(this,R)),t&&(console.info=a(this,k)),o&&(console.warn=a(this,I)),r&&this.removeOverrideError()}info(...e){return this.log(...e)}warn(...e){return this.log(...e)}table(...e){return this.isBrowser()?a(this,re).call(this,...e):this.buildTable(...e)}alert(...e){if(!this.isBrowser())return this.log(...e);let t=e.join(" | ");alert(t)}assert(e,t=!0,...o){let r;try{return typeof e=="function"?(r=e(...o),r!==t?(this.error("Asset failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0)):e!==t?(this.error("Assert failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0)}catch{this.error("Unexpected error in assert")}return!1}applyAnalogFormatting({activeTarget:e="",override:t=!1}={}){try{let r={STANDARD:null,TEST:{color:"#B18904",symbol:"diamonds"}};return this.setDefaultContext(r.DEFAULT),e&&this.setActiveTarget(e),this.setOptions({silent:!1,hideError:!1,hideHookMessage:!0,lidLenMax:6}),t&&(this.overrideConsole(),this.overrideError()),!0}catch(o){console.error({lid:3249},o.message)}return!1}applyPredefinedFormat(e=Le.DEFAULT_FORMAT,{activeTarget:t="",override:o=!1}={}){if(e===Le.DEFAULT_FORMAT)return this.applyAnalogFormatting({activeTarget:t,override:o})}convertToUrl({protocol:e,host:t,port:o,pathname:r}){if(!e||!t||!o||!r)return null;let s=new URL("http://localhost");return s.protocol=e,s.host=t,s.port=o,r&&(s.pathname=r),s.toString()}generateLogToRemoteUrl(e=null,{pathname:t=v.pathname}={}){if(typeof e=="string"||e instanceof String)return e;if(!this.isBrowser())return null;let o=this.options.protocol||window.location.protocol+"//",r=this.options.host||window.location.host||v.host,s=this.options.port||v.port;return t=this.options.pathname||t,this.convertToUrl({protocol:o,host:r,port:s,pathname:t})}addPlugin(e,t,o=""){o=o||e,this[e]=t,L.pluginTable[o]={type:ve.LOCAL,methodName:e,callback:t}}addGlobalPlugin(e,t,o){L[e]=t,L.pluginTable[o]={type:ve.GLOBAL,methodName:e,callback:t}}getPluginList(){return Object.keys(L.pluginTable)}validatePlugin(e){return L.pluginTable[e]?!0:(console.warn(`The plugin ${e} is not registered`),!1)}},_=L;S=new WeakMap,C=new WeakMap,M=new WeakMap,R=new WeakMap,k=new WeakMap,I=new WeakMap,B=new WeakMap,oe=new WeakMap,re=new WeakMap,ne=new WeakSet,Me=function(e){let t=this.generateNewContext(),o=Object.assign({},t,e);return o.color.toLowerCase().indexOf("rgb")>-1?o.color=Q.rgbStringToHex(o.color):o.color.indexOf("#")===-1&&(o.color=Q.colorNameToHex(o.color)),o},se=new WeakSet,ke=function(){try{this.setTargets(q),this.setLogLevels(E),this.setContexts(V)}catch(e){console.error({lid:4321},e.message)}return!1},m(_,"ALIGN",{LEFT:"LEFT",RIGHT:"RIGHT"}),m(_,"ENVIRONMENT_TYPE",{BROWSER:"BROWSER",NODE:"NODE",OTHER:"OTHER"}),m(_,"instanceCount",0),m(_,"pluginTable",{});var ct=_,Qe=_,ft=Qe,dt=new _;export{ct as AnaLogger,V as DEFAULT_LOG_CONTEXTS,E as DEFAULT_LOG_LEVELS,q as DEFAULT_LOG_TARGETS,dt as anaLogger,ft as default};
|
|
1
|
+
var Be=Object.defineProperty;var Ue=(n,e,t)=>e in n?Be(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var m=(n,e,t)=>(Ue(n,typeof e!="symbol"?e+"":e,t),t),ce=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var a=(n,e,t)=>(ce(n,e,"read from private field"),t?t.call(n):e.get(n)),A=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},fe=(n,e,t,o)=>(ce(n,e,"write to private field"),o?o.call(n,t):e.set(n,t),t);var J=(n,e,t)=>(ce(n,e,"access private method"),t);var be={Foreground:38,Background:48},F="\x1B[1D",Te="\x1B[0m"+F,z={Bold:"\x1B[1m"+F,Underline:"\x1B[4m"+F,Reversed:"\x1B[7m"+F},Ge={Bold:"\x1B[1m"+F,Underline:"\x1B[4m"+F,Reversed:"\x1B[7m"+F},de={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function Pe(n){return!!de[n]}var Oe=(n,e,t)=>n===e&&e===t?n<8?16:n>248?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(e/255*5)+Math.round(t/255*5),ye=n=>{let e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;n=n.replace(e,function(o,r,s,i){return r+r+s+s+i+i});let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return t?{red:parseInt(t[1],16),blue:parseInt(t[2],16),green:parseInt(t[3],16)}:{}},Ae=function({red:n,green:e,blue:t}){let o=n<<16|e<<8|t<<0;return"#"+(16777216+o).toString(16).slice(1)},xe=function(n){let e=n.matchAll(/\d+/g),t=[];for(let o of e){let r=parseInt(o[0]);if(r>255)return null;t.push(r)}return t.length!==3?null:{red:t[0],green:t[1],blue:t[2]}},je=function(n){let e=xe(n);return e&&Ae(e)},X=function(e,t,o){return o<0&&(o+=1),o>1&&(o-=1),o<1/6?e+(t-e)*6*o:o<1/2?t:o<2/3?e+(t-e)*(2/3-o)*6:e},Re=({hue:n,saturation:e,lightness:t})=>{let o,r,s;if(e===0)o=r=s=t;else{let i=t<.5?t*(1+e):t+e-t*e,l=2*t-i;o=X(l,i,n+1/3),r=X(l,i,n),s=X(l,i,n-1/3)}return{red:Math.round(o*255),blue:Math.round(s*255),green:Math.round(r*255)}},Ne=n=>{let e=n.toLowerCase();return typeof de[e]<"u"?de[e]:""};function P({red:n,blue:e,green:t},o=!0){if(n===void 0||e===void 0||t===void 0)return"";let r=Oe(n,e,t);return`\x1B[${o?be.Foreground:be.Background};5;`+r+"m "+F}function G(n,e=!0){let{red:t,green:o,blue:r}=ye(n);return P({red:t,green:o,blue:r},e)}function K({hue:n,saturation:e,lightness:t},o){let{red:r,green:s,blue:i}=Re({hue:n,saturation:e,lightness:t});return P({red:r,green:s,blue:i},o)}function he(n,e=!0){try{let t;return n=n||"",n?((typeof n=="string"||n instanceof String)&&(n=n.trim()),Pe(n)?(t=Ne(n),G(t,e)):typeof n=="object"&&!!n.red&&!!n.blue&&!!n.green?P(n,e):typeof n=="object"&&!!n.hue&&!!n.saturation&&!!n.lightness?K(n,e):n.startsWith("#")?G(n,e):(n=n.toString(),/^[\da-fA-F]+$/.test(n)?G("#"+n,e):"")):""}catch(t){console.error("TO_ANSI_INVALID_ARGUMENT_ERROR",t.message)}}function Q(n,{fg:e,bg:t,isUnderline:o=!1,isBold:r=!1,isReversed:s=!1}){let i=!1,l="";return e&&(i=!0,l=l+e),t&&(i=!0,l=l+t),o&&(i=!0,l=l+z.Underline),r&&(i=!0,l=l+z.Bold),s&&(i=!0,l=l+z.Reversed),i?l+n+Te:n}function qe(n,{fg:e={},bg:t={},isUnderline:o=!1,isBold:r=!1,isReversed:s=!1}){return e&&(e=P({...e})),t&&(t=P({...t},!1)),Q(n,{fg:e,bg:t,isUnderline:o,isBold:r,isReversed:s})}function We(n,{fg:e="",bg:t="",isUnderline:o=!1,isBold:r=!1,isReversed:s=!1}){return e&&(e=K({...e})),t&&(t=K({...t},!1)),Q(n,{fg:e,bg:t,isUnderline:o,isBold:r,isReversed:s})}function Ye(n,{fg:e="",bg:t="",isUnderline:o=!1,isBold:r=!1,isReversed:s=!1}){return e&&(e=G(e)),t&&(t=G(t,!1)),Q(n,{fg:e,bg:t,isUnderline:o,isBold:r,isReversed:s})}function $e(n,e=null){if(!e)return n;let{fg:t="",bg:o="",isUnderline:r=!1,isBold:s=!1,isReversed:i=!1}=e;return t&&(t=he(t)),o&&(o=he(o,!1)),Q(n,{fg:t,bg:o,isUnderline:r,isBold:s,isReversed:i})}var Z={fromRgb:P,fromHexa:G,fromHsl:K,fromColor:he,getTextFromRgb:qe,getTextFromHsl:We,getTextFromHex:Ye,getTextFromColor:$e,colorNameToHex:Ne,hslToRgb:Re,hexToRgb:ye,rgbToHex:Ae,rgbToAnsi256:Oe,rgbStringToRgb:xe,rgbStringToHex:je,hue2rgb:X,RESET:Te,FONT_STYLE:z,STYLE:Ge};var we={COLOR_TABLE:["#d2466e","#FFA07A","#FF7F50","#FF6347","#FFE4B5","#ADFF2F","#808000","#40E0D0","#1E90FF","#EE82EE","#708090","#DEB887","#FE642E","#210B61","#088A4B","#5E610B","#FA8258","#088A68","#B40431"],SYSTEM:{BROWSER:"BROWSER",NODE:"NODE"}},j=we.COLOR_TABLE,$=we.SYSTEM,ue=2e3,ge="analogger-removed-notif",pe="analogger-header",me="analogger-view",Le="analogger-footer",_e="to-esm-line",ee={TOP:"TOP",BOTTOM:"BOTTOM"},Fe="ANALOGGER",Ee={DEFAULT_FORMAT:"FORMAT1"};var{parse:st,stringify:Ve}=JSON,{keys:it}=Object,Je=String,ze="string";var Se="object",Xe=(n,e)=>e;var De=(n,e,t)=>{let o=Je(e.push(t)-1);return n.set(t,o),o};var ve=(n,e,t)=>{let o=e&&typeof e===Se?(g,f)=>g===""||-1<e.indexOf(g)?f:void 0:e||Xe,r=new Map,s=[],i=[],l=+De(r,s,o.call({"":n},"",n)),c=!l;for(;l<s.length;)c=!0,i[l]=Ve(s[l++],b,t);return"["+i.join(",")+"]";function b(g,f){if(c)return c=!c,f;let O=o.call(this,g,f);switch(typeof O){case Se:if(O===null)return O;case ze:return r.get(O)||De(r,s,O)}return O}};var Ke=()=>null,v={moduleName:"analogger",protocol:"http://",host:"localhost",port:12e3,pathname:"analogger",binarypathname:"uploaded",loopback:"localhost",consoleDomId:"#analogger",logFilename:"./analogger.log"},q={ALL:"ALL",USER:"USER"},E={FATAL:5e3,ERROR:4e3,WARN:3e3,INFO:2e3,LOG:1e3,DEBUG:500,ALL:200,OFF:0,INHERIT:-1},Ce={LOCAL:"local",GLOBAL:"global"},V={DEFAULT:{contextName:"DEFAULT",logLevel:E.LOG,symbol:"check"},LOG:{contextName:"LOG",logLevel:E.LOG,symbol:"check"},DEBUG:{contextName:"DEBUG",logLevel:E.DEBUG},INFO:{contextName:"INFO",logLevel:E.INFO,color:"#B18904",symbol:"diamonds"},WARN:{contextName:"WARN",logLevel:E.WARN,color:j[0],symbol:"cross"},ERROR:{contextName:"ERROR",logLevel:E.ERROR},CRITICAL:{contextName:"CRITICAL",logLevel:E.CRITICAL}},te=`
|
|
2
|
+
`,oe={airplane:"\u2708",anchor:"\u2693",arrow_backward:"\u25C0",arrow_double_up:"\u23EB",arrow_double_down:"\u23EC",arrow_forward:"\u25B6",arrow_lower_right:"\u2198",arrow_lower_left:"\u2199",arrow_right_hook:"\u21AA",arrow_up_down:"\u2195",arrow_upper_left:"\u2196",arrow_upper_right:"\u2197",ballot_box_with_check:"\u2611",biohazard:"\u2623",black_circle:"\u23FA",black_medium_small_square:"\u25FE",black_medium_square:"\u25FC",black_nib:"\u2712",black_small_square:"\u25AA",black_square:"\u23F9",chains:"\u26D3",check:"\u2714",chess_pawn:"\u265F",cloud_and_rain:"\u26C8",clubs:"\u2663",coffee:"\u2615",copyright:"\xA9",cross:"\u274C",diamonds:"\u2666",divisions_ign:"\u2797",double_triangle_right:"\u23ED",double_triangle_left:"\u23EE",email:"\u2709",eject:"\u23CF",exclamation_mark:"\u2757",fast_forward:"\u23E9",female_sign:"\u2640",fist:"\u270A",fuel_pump:"\u26FD",gear:"\u2699",hammer_and_pick:"\u2692",hand:"\u270B",hearts:"\u2665",infinity:"\u267E",information:"\u2139",left_right_arrow:"\u2194",leftwards_arrow_with_hook:"\u21A9",male_sign:"\u2642",minus_sign:"\u2796",no_entry:"\u26D4",partly_sunny:"\u26C5",pencil:"\u270F",phone:"\u260E",plus_sign:"\u2795",question:"\u2754",radioactive:"\u2622",raised_hand:"\u270B",recycle:"\u267B",registered:"\xAE",relaxed:"\u263A",rewind:"\u23EA",scissors:"\u2702",snowman:"\u2603",spades:"\u2660",sparkles:"\u2728",star:"\u2B50",sunny:"\u2600",tent:"\u26FA",trademark:"\u2122",triangle_with_vertical_bar:"\u23EF",umbrella:"\u2614",vertical_bars:"\u23F8",watch:"\u231A",white_frowning_face:"\u2639",white_medium_square:"\u25FB",white_medium_small_square:"\u25FD",white_small_square:"\u25AB",wheelchair:"\u267F",white_circle:"\u26AA",writing_hand:"\u270D"};function Me(){return typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node<"u"?$.NODE:$.BROWSER}var Qe=Me();function Ze(){return Qe===$.NODE}var et=["keepLogHistory","getLogHistory","table","buildTable","truncateMessage","truncateMessage","rawLog","rawInfo","rawWarn","rawError","hasSeenLid"],S,C,M,w,k,I,H,re,ne,se,ke,ie,Ie,le,He,L=class{constructor({name:e="default"}={}){A(this,se);A(this,ie);A(this,le);m(this,"system","");m(this,"instanceId","");m(this,"instanceName","");m(this,"logIndex",0);m(this,"logCounter",0);A(this,S,[]);A(this,C,{});A(this,M,{});m(this,"activeTargets",[]);m(this,"indexColor",0);m(this,"format","");m(this,"keepLog",!1);m(this,"logHistory",[]);m(this,"$containers",null);m(this,"options",{hideHookMessage:!1});A(this,w,console.log);A(this,k,console.info);A(this,I,console.warn);A(this,H,console.error);A(this,re,console.debug);A(this,ne,console.table);m(this,"originalFormatFunction");m(this,"removeDomOldEntries",e=>{if(e.childElementCount>ue){let o=Math.ceil(ue/10);for(let r=0;r<o;++r)e.removeChild(e.firstChild);return o}return 0});m(this,"scrollDivToBottom",e=>{let t=e.scrollHeight-(e.clientHeight+e.scrollTop),o=e.clientHeight||e.offsetHeight;t>o/2||(e.scrollTop=e.scrollHeight)});this.system=Me(),this.format=this.onBuildLog.bind(this),this.originalFormatFunction=this.format,this.instanceName=e,++L.instanceCount,this.instanceId=L.instanceCount+"-"+Date.now(),this.errorTargetHandler=this.onError.bind(this),this.errorUserTargetHandler=this.onErrorForUserTarget.bind(this),this.setOptions(this.options),this.rawLog=a(this,w),this.rawInfo=a(this,k),this.rawWarn=a(this,I),this.rawError=a(this,H),this.ALIGN=L.ALIGN,this.ENVIRONMENT_TYPE=L.ENVIRONMENT_TYPE,J(this,le,He).call(this),this.resetLogHistory()}getName(){return this.instanceName}getId(){return this.instanceId}keepLogHistory(){this.keepLog=!0}releaseLogHistory(){this.keepLog=!1}resetLogHistory(){this.logHistory=[]}addToLogHistory(e){e=e||{},this.logHistory.push(Object.assign({},e))}getLogHistory(e=!0,t=te){let o=this.logHistory||[],r=[];return o.forEach(s=>{let{text:i}=s;r.push(i)}),e?r.join(t):r}getRawLogHistory(){return this.logHistory||[]}hasSeenLid(e){this.logHistory=this.logHistory||[];for(let t=0;t<this.logHistory.length;++t){let r=(this.logHistory[t]||{}).context||{};if(e===r.lid)return!0}return!1}forceEnvironment(e){this.forcedSystem=e}isNode(){return this&&this.forcedSystem?this.forcedSystem===$.NODE:Ze()}isBrowser(){return!this.isNode()}resetLogger(){this.options={},this.options.timeLenMax=10,this.options.contextLenMax=10,this.options.idLenMax=5,this.options.lidLenMax=6,this.options.messageLenMax=void 0,this.options.symbolLenMax=60,this.options.hideHookMessage=void 0,this.options.hidePassingTests=void 0,this.options.hideLog=void 0,this.options.hideError=void 0,this.options.oneConsolePerContext=!0,this.options.logToDom=void 0,this.options.logToFile=void 0,this.options.logToRemote=void 0,this.options.logToRemoteUrl=void 0,this.options.logToRemoteBinaryUrl=void 0,this.options.logToDomlogToFile=void 0,this.options.protocol=void 0,this.options.host=void 0,this.options.port=void 0,this.options.pathname=void 0,this.options.binarypathname=void 0}resetOptions(){this.resetLogger()}setOptions({contextLenMax:e=10,idLenMax:t=5,lidLenMax:o=6,symbolLenMax:r=2,messageLenMax:s=void 0,hideLog:i=void 0,hideError:l=void 0,hideHookMessage:c=void 0,hidePassingTests:b=void 0,logToDom:g=void 0,logToFile:f=void 0,logToRemote:O=void 0,logToRemoteUrl:R=void 0,logToRemoteBinaryUrl:W=void 0,loopback:T=v.loopback,requiredLogLevel:p=E.LOG,oneConsolePerContext:B=void 0,silent:d=void 0,protocol:ae=void 0,host:h=void 0,port:u=void 0,pathname:y=void 0,binarypathname:N=void 0}=null){this.options.contextLenMax=e,this.options.idLenMax=t,this.options.lidLenMax=o,this.options.messageLenMax=s,this.options.symbolLenMax=r,this.options.requiredLogLevel=p;let D;d!==void 0?D=!!d:i!==void 0&&(D=!!i),[{hideLog:D},{oneConsolePerContext:B},{hideError:l},{hideHookMessage:c},{hidePassingTests:b},{logToRemote:O}].forEach(x=>{let U=Object.keys(x)[0],Y=x[U];Y!==void 0&&(this.options[U]=!!Y)}),[{logToRemoteBinaryUrl:W},{logToRemoteUrl:R},{loopback:T},{protocol:ae},{host:h},{port:u},{pathname:y},{binarypathname:N}].forEach(x=>{let U=Object.keys(x)[0],Y=x[U];Y!==void 0&&(this.options[U]=Y)}),g!==void 0&&(this.options.logToDom=g||v.consoleDomId),f===!1?this.options.logToFile=!1:f!==void 0&&(this.isBrowser()||(this.options.logToFile=f||v.logFilename),a(this,w).call(this,"LogToFile is not supported in this environment. "))}getOptions(){return this.options}truncateMessage(e="",{fit:t=0,align:o=L.ALIGN.LEFT,ellipsis:r="..."}={}){return e=""+e,t&&e.length>t&&(e=e.substring(0,t-r.length)+r),e=o===L.ALIGN.LEFT?e.padEnd(t," "):e.padStart(t," "),e}onBuildLog({contextName:e,message:t="",lid:o="",symbol:r=""}={}){let s=new Date,i=("0"+s.getHours()).slice(-2)+":"+("0"+s.getMinutes()).slice(-2)+":"+("0"+s.getSeconds()).slice(-2);return i=this.truncateMessage(i,{fit:this.options.timeLenMax}),e=this.truncateMessage(e,{fit:this.options.contextLenMax,align:L.ALIGN.RIGHT}),o=this.truncateMessage(o,{fit:this.options.lidLenMax}),this.options.messageLenMax!==void 0&&(t=this.truncateMessage(t,{fit:this.options.messageLenMax})),r=this.truncateMessage(r,{fit:this.options.symbolLenMax}),`[${i}] ${e}: (${o}) ${r} ${t}`}onErrorForUserTarget(e,...t){this.errorUserTargetHandler(e,...t)}onError(e,...t){e.target===a(this,C).USER&&this.onErrorForUserTarget(e,...t)}onDisplayLog(...e){this.log(...e)}assistStask(e){try{let t=e.stack.split(`
|
|
3
|
+
`),o=[];for(let r=0;r<t.length;++r){let s=t[r];o.push(s)}return o}catch(t){console.rawError(t.message)}return e.message}onDisplayError(...e){try{let t=-1,o=null;for(let r=0;r<e.length;++r){let s=e[r];if(s instanceof Error&&s.stack){t=r,o=this.assistStask(s)||[];break}}if(!o){this.error(...e);return}for(let r=0;r<o.length;++r)e[t]=o[r],this.error(...e)}catch(t){console.rawError(t)}}setLogFormat(e){if(typeof e!="function")return console.error("Invalid parameter for setFormat. It is expecting a function or method."),!1;this.format=e.bind(this)}resetLogFormatter(){this.format=this.originalFormatFunction}setErrorHandler(e){this.errorTargetHandler=e.bind(this)}setErrorHandlerForUserTarget(e){this.errorUserTargetHandler=e.bind(this)}isContextValid(e){return typeof e=="object"&&!Array.isArray(e)&&e!==null?e.hasOwnProperty("contextName")&&e.hasOwnProperty("target"):!1}setDefaultContext(e){this.setContext(V.DEFAULT.contextName,e)}generateDefaultContext(){let e=a(this,S)[V.DEFAULT.contextName]||{};return e=Object.assign({},{lid:"",contextName:V.DEFAULT.contextName,target:q.ALL,symbol:"\u26A1",color:j[1],logLevel:E.LOG},e),e.name=e.contextName,e.id=this.logIndex++,e}generateNewContext(){let e=this.generateDefaultContext();return e.color=j[this.indexColor++%(j.length-3)+2],e.symbol="",e}generateErrorContext(){let e=this.generateDefaultContext();return e.contextName=V.ERROR.contextName,e.name=e.contextName,e.color=j[0],e.symbol="\u274C",e.error=!0,e.logLevel=E.ERROR,e}setContext(e,t={}){t.contextName=e,t.name=e,t=J(this,ie,Ie).call(this,t),a(this,S)[e]=t}getContext(e){return a(this,S)[e]}setContexts(e){Object.keys(e).forEach(o=>{let r=e[o]||{};this.setContext(o,r),e[o]=a(this,S)[o]})}getContexts(){return Object.freeze(a(this,S))}setTargets(e={}){let t={};if(Array.isArray(e))try{for(let o=0;o<e.length;++o){let r=e[o];if(typeof r=="string"||r instanceof String)t[r]=r;else if(typeof r=="object"){let s=null;for(let i in r){let l=r[i];if(i=i.trim(),!i){console.error("Invalid target");break}if(typeof l=="string"||l instanceof String){l=l.trim(),s=[i,l];break}if(typeof l=="number")break}s&&(t[s[0]]=s[1])}}}catch(o){console.error({lid:4321},o.message)}else t=e;fe(this,C,Object.assign({},t,{...q}))}addTargets(e){let t=a(this,C),o=Object.assign({},t,e);this.setTargets(o)}getTargets(){return Object.freeze(a(this,C))}setActiveTargets(e=null){if(e===null){this.activeTargets=[q.ALL];return}else if(typeof e=="string"||e instanceof String)e=e.split(",");else if(typeof e=="object"||typeof e=="function")return;for(let t=0;t<e.length;++t)e[t]=e[t].trim();this.activeTargets=e}getActiveTarget(){return this.activeTargets}setActiveTarget(e){this.activeTargets=[],this.setActiveTargets(e),this.activeTargets=[this.activeTargets[0]]}setLogLevel(e,t){a(this,M)[e]=t}getLogLevel(e){return a(this,M)[e]}setLogLevels(e){fe(this,M,e)}getLogLevels(){return Object.freeze(a(this,M))}isTargetAllowed(e){return!e||!this.activeTargets||!this.activeTargets.length||e===q.ALL||this.activeTargets.includes(q.ALL)?!0:this.activeTargets.includes(e)}setColumns(e,t,o){let r=0;for(let i in t){if(!["contextName","symbol","lid","text"].includes(i))continue;let l=t[i],c=document.createElement("span");c.classList.add("analogger-col",`analogger-col-${i}`,`analogger-col-${r}`),++r,c.textContent=l,e.append(c)}let s=document.createElement("span");s.classList.add("analogger-col","analogger-col-text",`analogger-col-${r}`),s.textContent=o,e.append(s);for(let i=1;i<=3;++i)s=document.createElement("span"),s.classList.add("analogger-col","analogger-col-extra",`analogger-extra-${i}`),e.append(s)}checkOnLoggingToDom(e,t){try{let o=e.onLoggingToDom;return typeof o!="function"?void 0:o.call(this,e,t)}catch{}}addLineToDom(e,t,{context:o,addType:r,message:s,text:i,args:l}){if(this.checkOnLoggingToDom(o,{message:s,text:i,args:l,logCounter:this.logCounter,$view:e,$line:t,addType:r})===!1)return;if(r===ee.BOTTOM?e.append(t):e.insertBefore(t,e.firstChild),this.removeDomOldEntries(e)){if(e.getElementsByClassName(ge).length)return;this.showRemovedNotification(o);return}this.scrollDivToBottom(e)}showRemovedNotification(e){e.contextName=Fe,e.symbol="\u{1F5D1}",e.color="orange",e.className=ge,clearTimeout(this.timerAddLineToDomID),this.timerAddLineToDomID=setTimeout(()=>{this.timerAddLineToDomID=null,this.writeLogToDom(e,"",{addType:ee.TOP,message:"Oldest entries removed"})},500)}writeLogToDom(e,t,{addType:o=ee.BOTTOM,message:r="",args:s=null}={}){this.$containers=this.$containers||document.querySelectorAll(this.options.logToDom),t=r||t;for(let i=0;i<this.$containers.length;++i){let l=this.$containers[i],c=l.querySelector("."+pe);c||(c=document.createElement("div"),c.classList.add(pe),c.append(document.createElement("span")),c.append(document.createElement("span")),c.append(document.createElement("span")),l.append(c));let b=l.querySelector("."+me);b||(b=document.createElement("div"),b.classList.add(me),l.append(b));let g=l.querySelector("."+Le);g||(g=document.createElement("div"),g.classList.add(Le),g.append(document.createElement("span")),g.append(document.createElement("span")),g.append(document.createElement("span")),l.append(g));let f=document.createElement("div");f.classList.add(_e),e.className&&f.classList.add(e.className),f.style.color=e.color,this.setColumns(f,e,t,s),setTimeout(function(O,R,{addType:W,context:T,message:p,text:B,args:d}){this.addLineToDom(O,R,{addType:W,context:T,message:p,text:B,args:d})}.bind(this,b,f,{addType:o,context:e,message:r,text:t,args:s}),0)}}writeLogToFile(e){try{fs.appendFileSync(this.options.logToFilePath,e+this.EOL)}catch(t){console.rawError("LOG_TO_FILE_FAILURE: ",t.message)}}writeLogToRemote(...e){try{let t=this.generateLogToRemoteUrl(this.options.logToRemoteUrl);if(!t)return null;let o=[...e],r=JSON.stringify(o);fetch(t,{method:"post",body:r,headers:{"Content-Type":"application/json"}}).then(s=>s.json()).catch(()=>null)}catch(t){console.rawError("LOG_TO_REMOTE_FAILURE: ",t.message)}}uploadDataToRemote(e,t=null,o=null){try{if(!this.options.logToRemote)return;let r=this.generateLogToRemoteUrl(this.options.logToRemoteBinaryUrl,{pathname:v.binarypathname});if(!r)return null;let s=e;t&&(s=JSON.stringify({raw:e,context:t})),fetch(r,{method:"post",body:s}).then(i=>i.json()).then(i=>o&&o(i)).catch(i=>i)}catch(r){console.rawError("BINARY_TO_REMOTE_FAILURE: ",r.message)}}convertArgumentsToText(e){let t=[],o,r=e.length;for(let s=0;s<r;++s){let i,l=e[s];try{i=JSON.stringify(l)}catch{}if(!i)try{i=ve(l)}catch{}t.push(i)}return o=t.join("\u2022"),o}writeToConsole(e,t){let o=[e];this.isBrowser()&&o.push(`color: ${t.color}`);let r=t.contextLevel||E.LOG;r>=E.ERROR?a(this,H).call(this,...o):r>=E.WARN?a(this,I).call(this,...o):r>=E.INFO?a(this,k).call(this,...o):r>=E.LOG?a(this,w).call(this,...o):r>=E.DEBUG&&a(this,re).call(this,...o)}checkPlugins(e,{message:t,text:o,args:r,logCounter:s}){try{if(!Object.keys(L.pluginTable).length)return;let i=!0;for(let l in e){let c=e[l];if(!c)continue;let b=L.pluginTable[l];if(!b||typeof b!="object")continue;let{callback:g,methodName:f,type:O}=b;if(typeof g!="function")continue;g.call(this,e,{message:t,text:o,args:r,logCounter:s,methodName:f,type:O,pluginOptions:c})===!1&&(i=!1)}return i}catch{}}checkOnLogging(e,t){try{let o=e.onLogging;return typeof o!="function"?void 0:o.call(this,e,t)}catch{}}processOutput(e={}){try{let t="";if(this.applySymbolByName(e),!this.isTargetAllowed(e.target)||e.logLevel===E.OFF||this.options.requiredLogLevel>e.logLevel)return;let o=Array.prototype.slice.call(arguments,1);t=this.convertArgumentsToText(o);let r="",s="";s=this.format({...e,message:t}),this.keepLog&&this.addToLogHistory({context:e,message:t,text:s}),++this.logCounter;let i;if(i=this.checkOnLogging(e,{message:t,text:s,args:o,logCounter:this.logCounter}),i===!1||(i=this.checkPlugins(e,{message:t,text:s,args:o,logCounter:this.logCounter}),i===!1)||(this.options.logToRemote&&this.writeLogToRemote(e,...o),this.isBrowser()?(e.environnment=L.ENVIRONMENT_TYPE.BROWSER,this.options.logToDom&&this.writeLogToDom(e,s,{message:t,args:o}),r=`%c${s}`):(e.environnment=L.ENVIRONMENT_TYPE.NODE,r=Z.getTextFromColor(s,{fg:e.color,bg:e.bgColor,isBold:e.bold,isUnderline:e.underline,isReversed:e.reversed}),this.options.logToFile&&this.writeLogToFile(s)),this.options.hideLog))return;this.writeToConsole(r,e),this.errorTargetHandler(e,o)}catch(t){console.rawError("AnaLogger:",t.message)}}isExtendedOptionsPassed(e){return typeof e!="object"?!1:e.hasOwnProperty("context")||e.hasOwnProperty("target")||e.hasOwnProperty("color")||e.hasOwnProperty("contextName")||e.hasOwnProperty("lid")}extractContextFromInput(e){return(typeof e=="string"||e instanceof String)&&e.toLowerCase().indexOf("lid:")!==0,e}listSymbols(){for(let e in oe)console.rawLog(oe[e]+` ${e} `)}applySymbolByName(e){try{e.symbol&&oe[e.symbol]&&(e.symbol=oe[e.symbol])}catch{}}convertToContext(e,t){e=e||t;let o=e;if(e.context&&typeof e.context=="object"){let r=Object.assign({},e);delete r.context,o=Object.assign({},e.context,r)}return o=Object.assign({},t,o),delete o.context,o}log(e,...t){if(e=this.extractContextFromInput(e),!this.isExtendedOptionsPassed(e)){let s=this.generateDefaultContext();this.processOutput.apply(this,[s,e,...t]);return}let o=this.generateDefaultContext(),r=this.convertToContext(e,o);this.processOutput.apply(this,[r,...t])}error(e,...t){if(this.options.hideError)return;if(e=this.extractContextFromInput(e),!this.isExtendedOptionsPassed(e)){let i=this.generateErrorContext();this.processOutput.apply(this,[i,e,...t]);return}let o=this.generateErrorContext(),r=this.convertToContext(e,o),s=Array.prototype.slice.call(arguments,1);this.log(r,...s)}overrideError(){this.options.hideHookMessage||a(this,w).call(this,"AnaLogger: Hook placed on console.error"),console.error=this.onDisplayError.bind(this)}attachConsole(){try{return console.rawLog=a(this,w),console.raw=a(this,w),console.rawInfo=a(this,k),console.rawWarn=a(this,I),console.rawError=a(this,H),console.logHistory=this.logHistory,console.logHistory=this.logHistory,et.forEach(e=>{console[e]=function(...t){this[e](...t)}.bind(this)}),!0}catch(e){console.error({lid:4321},e.message)}return!1}overrideConsole({log:e=!0,info:t=!0,warn:o=!0,error:r=!1}={},s=null){this.options.hideHookMessage||a(this,w).call(this,"AnaLogger: Hook placed on console.log"),[{log:e},{info:t},{warn:o}].forEach(i=>{let l=Object.keys(i)[0];i[l]&&(console[l]=this.onDisplayLog.bind(this))}),r&&this.overrideError(),this.attachConsole()}removeOverrideError(){console.warn=a(this,H)}removeOverride({log:e=!0,info:t=!0,warn:o=!0,error:r=!1}={}){e&&(console.log=a(this,w)),t&&(console.info=a(this,k)),o&&(console.warn=a(this,I)),r&&this.removeOverrideError()}info(...e){return this.log(...e)}warn(...e){return this.log(...e)}table(...e){return this.isBrowser()?a(this,ne).call(this,...e):J(this,se,ke).call(this,...e)}alert(...e){if(!this.isBrowser())return this.log(...e);let t=e.join(" | ");alert(t)}assert(e,t=!0,...o){let r;try{return typeof e=="function"?(r=e(...o),r!==t?(this.error("Asset failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0)):e!==t?(this.error("Assert failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0)}catch{this.error("Unexpected error in assert")}return!1}applyAnalogFormatting({activeTarget:e="",override:t=!1}={}){try{let r={STANDARD:null,TEST:{color:"#B18904",symbol:"diamonds"}};return this.setDefaultContext(r.DEFAULT),e&&this.setActiveTarget(e),this.setOptions({silent:!1,hideError:!1,hideHookMessage:!0,lidLenMax:6}),t&&(this.overrideConsole(),this.overrideError()),!0}catch(o){console.error({lid:3249},o.message)}return!1}applyPredefinedFormat(e=Ee.DEFAULT_FORMAT,{activeTarget:t="",override:o=!1}={}){if(e===Ee.DEFAULT_FORMAT)return this.applyAnalogFormatting({activeTarget:t,override:o})}convertToUrl({protocol:e,host:t,port:o,pathname:r}){if(!e||!t||!o||!r)return null;let s=new URL("http://localhost");return s.protocol=e,s.host=t,s.port=o,r&&(s.pathname=r),s.toString()}generateLogToRemoteUrl(e=null,{pathname:t=v.pathname}={}){if(typeof e=="string"||e instanceof String)return e;if(!this.isBrowser())return null;let o=this.options.protocol||window.location.protocol+"//",r=this.options.host||window.location.host||v.host,s=this.options.port||v.port;return t=this.options.pathname||t,this.convertToUrl({protocol:o,host:r,port:s,pathname:t})}addPlugin(e,t,o=""){o=o||e,this[e]=t,L.pluginTable[o]={type:Ce.LOCAL,methodName:e,callback:t}}addGlobalPlugin(e,t,o){L[e]=t,L.pluginTable[o]={type:Ce.GLOBAL,methodName:e,callback:t}}getPluginList(){return Object.keys(L.pluginTable)}validatePlugin(e){return L.pluginTable[e]?!0:(console.warn(`The plugin ${e} is not registered`),!1)}},_=L;S=new WeakMap,C=new WeakMap,M=new WeakMap,w=new WeakMap,k=new WeakMap,I=new WeakMap,H=new WeakMap,re=new WeakMap,ne=new WeakMap,se=new WeakSet,ke=function(e,{ellipsis:t="...",ColumnMinChars:o=6,columnMaxChars:r=0,verticalSeparator:s=" \u2502 ",horizontalSeparator:i="\u2500",availableLength:l=0,onCompleteHeaders:c=null,onCompleteSeparators:b=null,onCompleteLines:g=null}={}){let f="";if(Array.isArray(e)||(e=Object.values(Object.values(e))),!e||!e.length)return"";let R=e.map(h=>Object.assign({},h)),W=R[0],T=Object.keys(W);R.unshift(T),i=i.repeat(100);let p={};for(let h=1;h<R.length;++h){let u=R[h];for(let y=0;y<T.length;++y){let N=T[y],D=u[N];p[N]=p[N]||0;let x;try{x=JSON.stringify(D).length}catch{}x=x||o,p[N]=Math.max(p[N],x,N.length)}}l||(l=Ke()||process.stdout.columns||120-s.length-1-5),l=l-4;let B=Object.values(p).reduce((h,u)=>h+u,0);if(l<B){let h=l/B;for(let u in p)p[u]=Math.floor(p[u]*h)-1,o&&p[u]<o&&(p[u]=o),r&&p[u]>r&&(p[u]=r),p[u]=p[u]}let d;d="";for(let h=0;h<T.length;++h){let u=T[h],y=p[u];d+=this.truncateMessage(u,{fit:y,ellipsis:t}),d+=s}c&&(d=c(d,T)),f+=this.truncateMessage(d,{fit:l}),f+=te,d="";let ae=i;for(let h=0;h<T.length;++h){let u=T[h],y=p[u];d+=this.truncateMessage(ae,{fit:y,ellipsis:""}),d+=s}b&&(d=b(d,T)),f+=this.truncateMessage(d,{fit:l}),f+=te;for(let h=1;h<R.length;++h){d="";let u=R[h];for(let y=0;y<T.length;++y){let N=T[y],D=u[N],x=p[N];d+=this.truncateMessage(D,{fit:x,ellipsis:t}),d+=s}g&&(d=g(d,u)),f+=this.truncateMessage(d,{fit:l}),f+=te}return this.rawLog(f),f},ie=new WeakSet,Ie=function(e){let t=this.generateNewContext(),o=Object.assign({},t,e);return o.color.toLowerCase().indexOf("rgb")>-1?o.color=Z.rgbStringToHex(o.color):o.color.indexOf("#")===-1&&(o.color=Z.colorNameToHex(o.color)),o},le=new WeakSet,He=function(){try{this.setTargets(q),this.setLogLevels(E),this.setContexts(V)}catch(e){console.error({lid:4321},e.message)}return!1},m(_,"ALIGN",{LEFT:"LEFT",RIGHT:"RIGHT"}),m(_,"ENVIRONMENT_TYPE",{BROWSER:"BROWSER",NODE:"NODE",OTHER:"OTHER"}),m(_,"instanceCount",0),m(_,"pluginTable",{});var ht=_,tt=_,ut=tt,gt=new _;export{ht as AnaLogger,V as DEFAULT_LOG_CONTEXTS,E as DEFAULT_LOG_LEVELS,q as DEFAULT_LOG_TARGETS,gt as anaLogger,ut as default};
|
|
4
4
|
|
package/esm/src/ana-logger.mjs
CHANGED
|
@@ -213,6 +213,21 @@ function isNode()
|
|
|
213
213
|
return currentSystem === SYSTEM.NODE;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
const COMMON_METHODS = [
|
|
217
|
+
"keepLogHistory",
|
|
218
|
+
"getLogHistory",
|
|
219
|
+
"table",
|
|
220
|
+
"buildTable",
|
|
221
|
+
"truncateMessage",
|
|
222
|
+
"truncateMessage",
|
|
223
|
+
"rawLog",
|
|
224
|
+
"rawInfo",
|
|
225
|
+
"rawWarn",
|
|
226
|
+
"rawError",
|
|
227
|
+
"hasSeenLid"
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
|
|
216
231
|
/**
|
|
217
232
|
* @module ____AnaLogger
|
|
218
233
|
* @class ____AnaLogger
|
|
@@ -292,24 +307,6 @@ class ____AnaLogger
|
|
|
292
307
|
this.rawWarn = this.#realConsoleWarn;
|
|
293
308
|
this.rawError = this.#realConsoleError;
|
|
294
309
|
|
|
295
|
-
console.rawLog = this.#realConsoleLog;
|
|
296
|
-
console.raw = this.#realConsoleLog;
|
|
297
|
-
|
|
298
|
-
console.rawInfo = this.#realConsoleInfo;
|
|
299
|
-
console.rawWarn = this.#realConsoleWarn;
|
|
300
|
-
console.rawError = this.#realConsoleError;
|
|
301
|
-
|
|
302
|
-
console.keepLogHistory = this.keepLogHistory;
|
|
303
|
-
console.getLogHistory = this.getLogHistory;
|
|
304
|
-
|
|
305
|
-
console.table = this.table;
|
|
306
|
-
console.buildTable = this.buildTable;
|
|
307
|
-
console.truncateMessage = this.truncateMessage;
|
|
308
|
-
console.rawLog = this.rawLog;
|
|
309
|
-
console.rawInfo = this.rawInfo;
|
|
310
|
-
console.rawWarn = this.rawWarn;
|
|
311
|
-
console.rawError = this.rawError;
|
|
312
|
-
|
|
313
310
|
this.ALIGN = ____AnaLogger.ALIGN;
|
|
314
311
|
this.ENVIRONMENT_TYPE = ____AnaLogger.ENVIRONMENT_TYPE;
|
|
315
312
|
|
|
@@ -343,22 +340,59 @@ class ____AnaLogger
|
|
|
343
340
|
this.logHistory = [];
|
|
344
341
|
}
|
|
345
342
|
|
|
343
|
+
addToLogHistory(obj)
|
|
344
|
+
{
|
|
345
|
+
obj = obj || {};
|
|
346
|
+
this.logHistory.push(Object.assign({}, obj));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Returns log entries
|
|
351
|
+
* @note This method should return the list of objects rather than
|
|
352
|
+
* the array of text
|
|
353
|
+
* @param join
|
|
354
|
+
* @param symbol
|
|
355
|
+
* @returns {string|*[]}
|
|
356
|
+
*/
|
|
346
357
|
getLogHistory(join = true, symbol = EOL)
|
|
347
358
|
{
|
|
348
|
-
const historyLog = this.logHistory;
|
|
349
|
-
|
|
359
|
+
const historyLog = this.logHistory || [];
|
|
360
|
+
const history = [];
|
|
361
|
+
historyLog.forEach((logEntry) =>
|
|
350
362
|
{
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
363
|
+
const {text} = logEntry;
|
|
364
|
+
history.push(text);
|
|
365
|
+
});
|
|
366
|
+
|
|
355
367
|
if (!join)
|
|
356
368
|
{
|
|
357
369
|
return history;
|
|
358
370
|
}
|
|
371
|
+
|
|
359
372
|
return history.join(symbol);
|
|
360
373
|
}
|
|
361
374
|
|
|
375
|
+
getRawLogHistory()
|
|
376
|
+
{
|
|
377
|
+
return this.logHistory || [];
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
hasSeenLid(lid)
|
|
381
|
+
{
|
|
382
|
+
this.logHistory = this.logHistory || [];
|
|
383
|
+
for (let i = 0; i < this.logHistory.length; ++i)
|
|
384
|
+
{
|
|
385
|
+
const log = this.logHistory[i] || {};
|
|
386
|
+
const context = log.context || {};
|
|
387
|
+
if (lid === context.lid)
|
|
388
|
+
{
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
|
|
362
396
|
forceEnvironment(system)
|
|
363
397
|
{
|
|
364
398
|
this.forcedSystem = system;
|
|
@@ -562,7 +596,7 @@ class ____AnaLogger
|
|
|
562
596
|
* @param onCompleteSeparators
|
|
563
597
|
* @param onCompleteLines
|
|
564
598
|
*/
|
|
565
|
-
buildTable(objList, {
|
|
599
|
+
#buildTable(objList, {
|
|
566
600
|
ellipsis = "...",
|
|
567
601
|
ColumnMinChars = 6,
|
|
568
602
|
columnMaxChars = 0,
|
|
@@ -1572,13 +1606,13 @@ class ____AnaLogger
|
|
|
1572
1606
|
let proceedFurther = true;
|
|
1573
1607
|
for (let keyName in context)
|
|
1574
1608
|
{
|
|
1575
|
-
const
|
|
1609
|
+
const pluginOptions = context[keyName];
|
|
1576
1610
|
|
|
1577
1611
|
/**
|
|
1578
1612
|
* The key has been passed in the context, but has a falsy value,
|
|
1579
1613
|
* so let's ignore it
|
|
1580
1614
|
*/
|
|
1581
|
-
if (!
|
|
1615
|
+
if (!pluginOptions)
|
|
1582
1616
|
{
|
|
1583
1617
|
continue;
|
|
1584
1618
|
}
|
|
@@ -1614,18 +1648,18 @@ class ____AnaLogger
|
|
|
1614
1648
|
continue;
|
|
1615
1649
|
}
|
|
1616
1650
|
|
|
1617
|
-
/**
|
|
1618
|
-
* If the key given in the context was a function, invoke that function
|
|
1619
|
-
*/
|
|
1620
|
-
if (typeof pluginArgs === "function")
|
|
1621
|
-
{
|
|
1622
|
-
context = pluginArgs;
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
1651
|
/**
|
|
1626
1652
|
* Invoke the plugin
|
|
1627
1653
|
*/
|
|
1628
|
-
let res = callback.call(this, context, {
|
|
1654
|
+
let res = callback.call(this, context, {
|
|
1655
|
+
message,
|
|
1656
|
+
text,
|
|
1657
|
+
args,
|
|
1658
|
+
logCounter,
|
|
1659
|
+
methodName,
|
|
1660
|
+
type,
|
|
1661
|
+
pluginOptions
|
|
1662
|
+
});
|
|
1629
1663
|
|
|
1630
1664
|
// If the plugin returns exactly false, the log entry will be ignored by anaLogger
|
|
1631
1665
|
if (res === false)
|
|
@@ -1699,6 +1733,11 @@ class ____AnaLogger
|
|
|
1699
1733
|
let text = "";
|
|
1700
1734
|
text = this.format({...context, message});
|
|
1701
1735
|
|
|
1736
|
+
if (this.keepLog)
|
|
1737
|
+
{
|
|
1738
|
+
this.addToLogHistory({context, message, text});
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1702
1741
|
++this.logCounter;
|
|
1703
1742
|
|
|
1704
1743
|
let proceedFurther;
|
|
@@ -1753,11 +1792,6 @@ class ____AnaLogger
|
|
|
1753
1792
|
}
|
|
1754
1793
|
}
|
|
1755
1794
|
|
|
1756
|
-
if (this.keepLog)
|
|
1757
|
-
{
|
|
1758
|
-
this.logHistory.push(output);
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
1795
|
if (this.options.hideLog)
|
|
1762
1796
|
{
|
|
1763
1797
|
return;
|
|
@@ -1922,32 +1956,60 @@ class ____AnaLogger
|
|
|
1922
1956
|
console.error = this.onDisplayError.bind(this);
|
|
1923
1957
|
}
|
|
1924
1958
|
|
|
1925
|
-
|
|
1959
|
+
attachConsole()
|
|
1926
1960
|
{
|
|
1927
|
-
|
|
1961
|
+
try
|
|
1928
1962
|
{
|
|
1929
|
-
this.#realConsoleLog
|
|
1930
|
-
|
|
1963
|
+
console.rawLog = this.#realConsoleLog;
|
|
1964
|
+
console.raw = this.#realConsoleLog;
|
|
1931
1965
|
|
|
1932
|
-
|
|
1966
|
+
console.rawInfo = this.#realConsoleInfo;
|
|
1967
|
+
console.rawWarn = this.#realConsoleWarn;
|
|
1968
|
+
console.rawError = this.#realConsoleError;
|
|
1969
|
+
|
|
1970
|
+
console.logHistory = this.logHistory;
|
|
1971
|
+
|
|
1972
|
+
console.logHistory = this.logHistory;
|
|
1973
|
+
COMMON_METHODS.forEach((name) =>
|
|
1974
|
+
{
|
|
1975
|
+
console[name] = function (...args)
|
|
1976
|
+
{
|
|
1977
|
+
this[name](...args);
|
|
1978
|
+
}.bind(this);
|
|
1979
|
+
});
|
|
1980
|
+
|
|
1981
|
+
return true;
|
|
1982
|
+
}
|
|
1983
|
+
catch (e)
|
|
1933
1984
|
{
|
|
1934
|
-
console.
|
|
1985
|
+
console.error({lid: 4321}, e.message);
|
|
1935
1986
|
}
|
|
1936
1987
|
|
|
1937
|
-
|
|
1988
|
+
return false;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
overrideConsole({log = true, info = true, warn = true, error = false} = {}, Console = null)
|
|
1992
|
+
{
|
|
1993
|
+
if (!this.options.hideHookMessage)
|
|
1938
1994
|
{
|
|
1939
|
-
|
|
1995
|
+
this.#realConsoleLog("AnaLogger: Hook placed on console.log");
|
|
1940
1996
|
}
|
|
1941
1997
|
|
|
1942
|
-
|
|
1998
|
+
[{log}, {info}, {warn}, ].forEach((methodObj)=>
|
|
1943
1999
|
{
|
|
1944
|
-
|
|
1945
|
-
|
|
2000
|
+
const methodName = Object.keys(methodObj)[0];
|
|
2001
|
+
if (methodObj[methodName])
|
|
2002
|
+
{
|
|
2003
|
+
console[methodName] = this.onDisplayLog.bind(this);
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
1946
2006
|
|
|
1947
2007
|
if (error)
|
|
1948
2008
|
{
|
|
1949
2009
|
this.overrideError();
|
|
1950
2010
|
}
|
|
2011
|
+
|
|
2012
|
+
this.attachConsole();
|
|
1951
2013
|
}
|
|
1952
2014
|
|
|
1953
2015
|
removeOverrideError()
|
|
@@ -1996,7 +2058,7 @@ class ____AnaLogger
|
|
|
1996
2058
|
return this.#realConsoleTable(...args);
|
|
1997
2059
|
}
|
|
1998
2060
|
|
|
1999
|
-
return this
|
|
2061
|
+
return this.#buildTable(...args);
|
|
2000
2062
|
}
|
|
2001
2063
|
|
|
2002
2064
|
alert(...args)
|
package/package.json
CHANGED
package/src/ana-logger.cjs
CHANGED
|
@@ -207,6 +207,21 @@ function isNode()
|
|
|
207
207
|
return currentSystem === SYSTEM.NODE;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
const COMMON_METHODS = [
|
|
211
|
+
"keepLogHistory",
|
|
212
|
+
"getLogHistory",
|
|
213
|
+
"table",
|
|
214
|
+
"buildTable",
|
|
215
|
+
"truncateMessage",
|
|
216
|
+
"truncateMessage",
|
|
217
|
+
"rawLog",
|
|
218
|
+
"rawInfo",
|
|
219
|
+
"rawWarn",
|
|
220
|
+
"rawError",
|
|
221
|
+
"hasSeenLid"
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
|
|
210
225
|
/**
|
|
211
226
|
* @module ____AnaLogger
|
|
212
227
|
* @class ____AnaLogger
|
|
@@ -286,24 +301,6 @@ class ____AnaLogger
|
|
|
286
301
|
this.rawWarn = this.#realConsoleWarn;
|
|
287
302
|
this.rawError = this.#realConsoleError;
|
|
288
303
|
|
|
289
|
-
console.rawLog = this.#realConsoleLog;
|
|
290
|
-
console.raw = this.#realConsoleLog;
|
|
291
|
-
|
|
292
|
-
console.rawInfo = this.#realConsoleInfo;
|
|
293
|
-
console.rawWarn = this.#realConsoleWarn;
|
|
294
|
-
console.rawError = this.#realConsoleError;
|
|
295
|
-
|
|
296
|
-
console.keepLogHistory = this.keepLogHistory;
|
|
297
|
-
console.getLogHistory = this.getLogHistory;
|
|
298
|
-
|
|
299
|
-
console.table = this.table;
|
|
300
|
-
console.buildTable = this.buildTable;
|
|
301
|
-
console.truncateMessage = this.truncateMessage;
|
|
302
|
-
console.rawLog = this.rawLog;
|
|
303
|
-
console.rawInfo = this.rawInfo;
|
|
304
|
-
console.rawWarn = this.rawWarn;
|
|
305
|
-
console.rawError = this.rawError;
|
|
306
|
-
|
|
307
304
|
this.ALIGN = ____AnaLogger.ALIGN;
|
|
308
305
|
this.ENVIRONMENT_TYPE = ____AnaLogger.ENVIRONMENT_TYPE;
|
|
309
306
|
|
|
@@ -337,22 +334,59 @@ class ____AnaLogger
|
|
|
337
334
|
this.logHistory = [];
|
|
338
335
|
}
|
|
339
336
|
|
|
337
|
+
addToLogHistory(obj)
|
|
338
|
+
{
|
|
339
|
+
obj = obj || {};
|
|
340
|
+
this.logHistory.push(Object.assign({}, obj));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Returns log entries
|
|
345
|
+
* @note This method should return the list of objects rather than
|
|
346
|
+
* the array of text
|
|
347
|
+
* @param join
|
|
348
|
+
* @param symbol
|
|
349
|
+
* @returns {string|*[]}
|
|
350
|
+
*/
|
|
340
351
|
getLogHistory(join = true, symbol = EOL)
|
|
341
352
|
{
|
|
342
|
-
const historyLog = this.logHistory;
|
|
343
|
-
|
|
353
|
+
const historyLog = this.logHistory || [];
|
|
354
|
+
const history = [];
|
|
355
|
+
historyLog.forEach((logEntry) =>
|
|
344
356
|
{
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
357
|
+
const {text} = logEntry;
|
|
358
|
+
history.push(text);
|
|
359
|
+
});
|
|
360
|
+
|
|
349
361
|
if (!join)
|
|
350
362
|
{
|
|
351
363
|
return history;
|
|
352
364
|
}
|
|
365
|
+
|
|
353
366
|
return history.join(symbol);
|
|
354
367
|
}
|
|
355
368
|
|
|
369
|
+
getRawLogHistory()
|
|
370
|
+
{
|
|
371
|
+
return this.logHistory || [];
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
hasSeenLid(lid)
|
|
375
|
+
{
|
|
376
|
+
this.logHistory = this.logHistory || [];
|
|
377
|
+
for (let i = 0; i < this.logHistory.length; ++i)
|
|
378
|
+
{
|
|
379
|
+
const log = this.logHistory[i] || {};
|
|
380
|
+
const context = log.context || {};
|
|
381
|
+
if (lid === context.lid)
|
|
382
|
+
{
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
|
|
356
390
|
forceEnvironment(system)
|
|
357
391
|
{
|
|
358
392
|
this.forcedSystem = system;
|
|
@@ -558,7 +592,7 @@ class ____AnaLogger
|
|
|
558
592
|
* @param onCompleteSeparators
|
|
559
593
|
* @param onCompleteLines
|
|
560
594
|
*/
|
|
561
|
-
buildTable(objList, {
|
|
595
|
+
#buildTable(objList, {
|
|
562
596
|
ellipsis = "...",
|
|
563
597
|
ColumnMinChars = 6,
|
|
564
598
|
columnMaxChars = 0,
|
|
@@ -1568,13 +1602,13 @@ class ____AnaLogger
|
|
|
1568
1602
|
let proceedFurther = true;
|
|
1569
1603
|
for (let keyName in context)
|
|
1570
1604
|
{
|
|
1571
|
-
const
|
|
1605
|
+
const pluginOptions = context[keyName];
|
|
1572
1606
|
|
|
1573
1607
|
/**
|
|
1574
1608
|
* The key has been passed in the context, but has a falsy value,
|
|
1575
1609
|
* so let's ignore it
|
|
1576
1610
|
*/
|
|
1577
|
-
if (!
|
|
1611
|
+
if (!pluginOptions)
|
|
1578
1612
|
{
|
|
1579
1613
|
continue;
|
|
1580
1614
|
}
|
|
@@ -1610,18 +1644,18 @@ class ____AnaLogger
|
|
|
1610
1644
|
continue;
|
|
1611
1645
|
}
|
|
1612
1646
|
|
|
1613
|
-
/**
|
|
1614
|
-
* If the key given in the context was a function, invoke that function
|
|
1615
|
-
*/
|
|
1616
|
-
if (typeof pluginArgs === "function")
|
|
1617
|
-
{
|
|
1618
|
-
context = pluginArgs;
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
1647
|
/**
|
|
1622
1648
|
* Invoke the plugin
|
|
1623
1649
|
*/
|
|
1624
|
-
let res = callback.call(this, context, {
|
|
1650
|
+
let res = callback.call(this, context, {
|
|
1651
|
+
message,
|
|
1652
|
+
text,
|
|
1653
|
+
args,
|
|
1654
|
+
logCounter,
|
|
1655
|
+
methodName,
|
|
1656
|
+
type,
|
|
1657
|
+
pluginOptions
|
|
1658
|
+
});
|
|
1625
1659
|
|
|
1626
1660
|
// If the plugin returns exactly false, the log entry will be ignored by anaLogger
|
|
1627
1661
|
if (res === false)
|
|
@@ -1695,6 +1729,11 @@ class ____AnaLogger
|
|
|
1695
1729
|
let text = "";
|
|
1696
1730
|
text = this.format({...context, message});
|
|
1697
1731
|
|
|
1732
|
+
if (this.keepLog)
|
|
1733
|
+
{
|
|
1734
|
+
this.addToLogHistory({context, message, text});
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1698
1737
|
++this.logCounter;
|
|
1699
1738
|
|
|
1700
1739
|
let proceedFurther;
|
|
@@ -1749,11 +1788,6 @@ class ____AnaLogger
|
|
|
1749
1788
|
}
|
|
1750
1789
|
}
|
|
1751
1790
|
|
|
1752
|
-
if (this.keepLog)
|
|
1753
|
-
{
|
|
1754
|
-
this.logHistory.push(output);
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
1791
|
if (this.options.hideLog)
|
|
1758
1792
|
{
|
|
1759
1793
|
return;
|
|
@@ -1918,32 +1952,60 @@ class ____AnaLogger
|
|
|
1918
1952
|
console.error = this.onDisplayError.bind(this);
|
|
1919
1953
|
}
|
|
1920
1954
|
|
|
1921
|
-
|
|
1955
|
+
attachConsole()
|
|
1922
1956
|
{
|
|
1923
|
-
|
|
1957
|
+
try
|
|
1924
1958
|
{
|
|
1925
|
-
this.#realConsoleLog
|
|
1926
|
-
|
|
1959
|
+
console.rawLog = this.#realConsoleLog;
|
|
1960
|
+
console.raw = this.#realConsoleLog;
|
|
1927
1961
|
|
|
1928
|
-
|
|
1962
|
+
console.rawInfo = this.#realConsoleInfo;
|
|
1963
|
+
console.rawWarn = this.#realConsoleWarn;
|
|
1964
|
+
console.rawError = this.#realConsoleError;
|
|
1965
|
+
|
|
1966
|
+
console.logHistory = this.logHistory;
|
|
1967
|
+
|
|
1968
|
+
console.logHistory = this.logHistory;
|
|
1969
|
+
COMMON_METHODS.forEach((name) =>
|
|
1970
|
+
{
|
|
1971
|
+
console[name] = function (...args)
|
|
1972
|
+
{
|
|
1973
|
+
this[name](...args);
|
|
1974
|
+
}.bind(this);
|
|
1975
|
+
});
|
|
1976
|
+
|
|
1977
|
+
return true;
|
|
1978
|
+
}
|
|
1979
|
+
catch (e)
|
|
1929
1980
|
{
|
|
1930
|
-
console.
|
|
1981
|
+
console.error({lid: 4321}, e.message);
|
|
1931
1982
|
}
|
|
1932
1983
|
|
|
1933
|
-
|
|
1984
|
+
return false;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
overrideConsole({log = true, info = true, warn = true, error = false} = {}, Console = null)
|
|
1988
|
+
{
|
|
1989
|
+
if (!this.options.hideHookMessage)
|
|
1934
1990
|
{
|
|
1935
|
-
|
|
1991
|
+
this.#realConsoleLog("AnaLogger: Hook placed on console.log");
|
|
1936
1992
|
}
|
|
1937
1993
|
|
|
1938
|
-
|
|
1994
|
+
[{log}, {info}, {warn}, ].forEach((methodObj)=>
|
|
1939
1995
|
{
|
|
1940
|
-
|
|
1941
|
-
|
|
1996
|
+
const methodName = Object.keys(methodObj)[0];
|
|
1997
|
+
if (methodObj[methodName])
|
|
1998
|
+
{
|
|
1999
|
+
console[methodName] = this.onDisplayLog.bind(this);
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
1942
2002
|
|
|
1943
2003
|
if (error)
|
|
1944
2004
|
{
|
|
1945
2005
|
this.overrideError();
|
|
1946
2006
|
}
|
|
2007
|
+
|
|
2008
|
+
this.attachConsole();
|
|
1947
2009
|
}
|
|
1948
2010
|
|
|
1949
2011
|
removeOverrideError()
|
|
@@ -1992,7 +2054,7 @@ class ____AnaLogger
|
|
|
1992
2054
|
return this.#realConsoleTable(...args);
|
|
1993
2055
|
}
|
|
1994
2056
|
|
|
1995
|
-
return this
|
|
2057
|
+
return this.#buildTable(...args);
|
|
1996
2058
|
}
|
|
1997
2059
|
|
|
1998
2060
|
alert(...args)
|
|
@@ -28,11 +28,18 @@ const PLUGIN_NAME = "takeScreenshot";
|
|
|
28
28
|
* @param text
|
|
29
29
|
* @param methodName
|
|
30
30
|
* @param type
|
|
31
|
+
* @example
|
|
32
|
+
* anaLogger.log({lid: 1234, takeScreenshot: {
|
|
33
|
+
* divSource: document.body,n
|
|
34
|
+
* onScreenshot: () => {},
|
|
35
|
+
* onResponse: () => {},
|
|
36
|
+
* filter : {width: 500,}
|
|
37
|
+
* }}, "Take a screenshot 500px wide")
|
|
31
38
|
* @returns {boolean}
|
|
32
39
|
*/
|
|
33
40
|
const takeScreenshot = (context,
|
|
34
41
|
{
|
|
35
|
-
|
|
42
|
+
pluginOptions = {},
|
|
36
43
|
divSource = document.body,
|
|
37
44
|
args = null,
|
|
38
45
|
logCounter = -1,
|
|
@@ -44,14 +51,15 @@ const takeScreenshot = (context,
|
|
|
44
51
|
{
|
|
45
52
|
try
|
|
46
53
|
{
|
|
54
|
+
pluginOptions.options = pluginOptions.options || {};
|
|
47
55
|
htmlToImage
|
|
48
|
-
.toPng(divSource)
|
|
56
|
+
.toPng(divSource, pluginOptions.options)
|
|
49
57
|
.then(function (imageData)
|
|
50
58
|
{
|
|
51
59
|
// ------------------------------------
|
|
52
60
|
// Phase 1: We have the screenshot
|
|
53
61
|
// ------------------------------------
|
|
54
|
-
const onScreenshot =
|
|
62
|
+
const onScreenshot = pluginOptions ? pluginOptions.onScreenshot : null;
|
|
55
63
|
onScreenshot && onScreenshot({
|
|
56
64
|
imageData,
|
|
57
65
|
context,
|
|
@@ -68,7 +76,7 @@ const takeScreenshot = (context,
|
|
|
68
76
|
// ------------------------------------
|
|
69
77
|
// Phase 1: We have the screenshot url from the server
|
|
70
78
|
// ------------------------------------
|
|
71
|
-
const onResponse =
|
|
79
|
+
const onResponse = pluginOptions ? pluginOptions.onResponse : null;
|
|
72
80
|
// We transfer as much information as we can to the plugin
|
|
73
81
|
onResponse && onResponse({
|
|
74
82
|
imageData,
|
|
@@ -96,8 +104,6 @@ const takeScreenshot = (context,
|
|
|
96
104
|
console.error({lid: 4321}, e.message);
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
response = false;
|
|
100
|
-
return response;
|
|
101
107
|
};
|
|
102
108
|
|
|
103
109
|
anaLogger.addPlugin(PLUGIN_NAME, takeScreenshot);
|