@@ -49,7 +49,7 @@ export class Logger implements AsyncDisposable {
49
49
#prefix: string | undefined ;
50
50
#attrs: Attributes | undefined ;
51
51
#writers: [ LogWriter , ...LogWriter [ ] ] ;
52
- #pendingWrites = new Set < Promise < void > > ( ) ;
52
+ #pendingWrites?: Set < Promise < void > > ;
53
53
54
54
constructor ( opts : LoggerOptions = { } ) {
55
55
let logLevelEnv = getEnv ( 'LOG_LEVEL' ) ;
@@ -106,11 +106,12 @@ export class Logger implements AsyncDisposable {
106
106
for ( const w of this . #writers) {
107
107
const write$ = w . write ( level , attrs , msg ) ;
108
108
if ( isPromise ( write$ ) ) {
109
+ this . #pendingWrites ??= new Set ( ) ;
109
110
this . #pendingWrites. add ( write$ ) ;
110
111
write$
111
112
. then ( ( ) => {
112
113
// we remove from pending writes only if the write was successful
113
- this . #pendingWrites. delete ( write$ ) ;
114
+ this . #pendingWrites! . delete ( write$ ) ;
114
115
} )
115
116
. catch ( ( e ) => {
116
117
// otherwise we keep in the pending write to throw on flush
@@ -121,14 +122,14 @@ export class Logger implements AsyncDisposable {
121
122
}
122
123
123
124
public flush ( ) {
124
- if ( this . #pendingWrites. size ) {
125
+ if ( this . #pendingWrites? .size ) {
125
126
const errs : unknown [ ] = [ ] ;
126
127
return Promise . allSettled (
127
128
Array . from ( this . #pendingWrites) . map ( ( w ) =>
128
129
w . catch ( ( err ) => errs . push ( err ) ) ,
129
130
) ,
130
131
) . then ( ( ) => {
131
- this . #pendingWrites. clear ( ) ;
132
+ this . #pendingWrites! . clear ( ) ;
132
133
if ( errs . length ) {
133
134
throw new AggregateError (
134
135
errs ,
0 commit comments