1
1
"use strict" ;
2
2
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
3
+ const SORT_ME_LAST_UNICODE = "\uFFFF" ;
3
4
/*
4
5
* Since the config and server startup functions are a big mix of sync/async, the logging often
5
6
* gets weird, so this helper class will store the logs during execution, then flush them to
@@ -19,16 +20,34 @@ class Logger {
19
20
const seq = this . sequence ++ ;
20
21
this . logs . push ( { sequence : seq , ...logEntry } ) ;
21
22
}
23
+ // we only want to print some things during startup (not during lint)
24
+ printDuringStartup ( entry ) {
25
+ // CHILD_PROCESS is only true during startup
26
+ if ( process . env . CHILD_PROCESS ) {
27
+ console . log ( entry ) ;
28
+ }
29
+ }
22
30
flushLogs ( ) {
23
31
this . logs
24
32
. sort ( ( a , b ) => {
25
33
var _a , _b , _c , _d ;
26
- // First, sort by domain
27
- if ( ( ( _a = a . domain ) !== null && _a !== void 0 ? _a : "\uFFFF" ) < ( ( _b = b . domain ) !== null && _b !== void 0 ? _b : "\uFFFF" ) )
34
+ /*
35
+ * Sorting the logs can be a bit tricky. We want to sort all the log messages by the domain
36
+ * name that threw the log.. but many logs are thrown without a specific domain name
37
+ * attached. We can sort those too of course, but we always want them to come at the very
38
+ * end of the logs, because in practice it makes way more sense to read them this way.
39
+ * So the best way I found to do that, maybe it's hacky, but if a domain isn't there we
40
+ * sort that log as if it were the very last unicode character, so no domain name could
41
+ * ever come after it. Yes, we could probably do an extra if statement and just return
42
+ * `1`, but this felt like the most intuitive way to implement and talk about this concept.
43
+ */
44
+ if ( ( ( _a = a . domain ) !== null && _a !== void 0 ? _a : SORT_ME_LAST_UNICODE ) <
45
+ ( ( _b = b . domain ) !== null && _b !== void 0 ? _b : SORT_ME_LAST_UNICODE ) )
28
46
return - 1 ;
29
- if ( ( ( _c = a . domain ) !== null && _c !== void 0 ? _c : "\uFFFF" ) > ( ( _d = b . domain ) !== null && _d !== void 0 ? _d : "\uFFFF" ) )
47
+ if ( ( ( _c = a . domain ) !== null && _c !== void 0 ? _c : SORT_ME_LAST_UNICODE ) >
48
+ ( ( _d = b . domain ) !== null && _d !== void 0 ? _d : SORT_ME_LAST_UNICODE ) )
30
49
return 1 ;
31
- // If domains are equal or non existent, compare by sequence
50
+ // If domains are equal ( or both non existent) , compare by sequence
32
51
return a . sequence - b . sequence ;
33
52
} )
34
53
. forEach ( ( log ) => {
0 commit comments