@@ -11,8 +11,8 @@ export class BackgroundBehavior {
1111 behaviorLog ( msg , "error" ) ;
1212 }
1313
14- log ( msg ) {
15- behaviorLog ( msg , "info" ) ;
14+ log ( msg , type = "info" ) {
15+ behaviorLog ( msg , type ) ;
1616 }
1717}
1818
@@ -155,7 +155,8 @@ export class BehaviorRunner extends BackgroundBehavior {
155155 let { state, opts} = behavior . init ( ) ;
156156 state = state || { } ;
157157 opts = opts ? { ...opts , ...mainOpts } : mainOpts ;
158- const log = behaviorLog ;
158+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159+ const log = async ( data : any , type : string ) => this . wrappedLog ( data , type ) ;
159160
160161 this . ctx = { Lib, state, opts, log } ;
161162
@@ -164,6 +165,17 @@ export class BehaviorRunner extends BackgroundBehavior {
164165 this . _unpause = null ;
165166 }
166167
168+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
169+ wrappedLog ( data : any , type = "info" ) {
170+ let logData ;
171+ if ( typeof data === "string" || data instanceof String ) {
172+ logData = { msg : data }
173+ } else {
174+ logData = data ;
175+ }
176+ this . log ( { ...logData , behavior : this . behaviorProps . id , siteSpecific : true } , type ) ;
177+ }
178+
167179 start ( ) {
168180 this . _running = this . run ( ) ;
169181 }
@@ -175,20 +187,16 @@ export class BehaviorRunner extends BackgroundBehavior {
175187 async run ( ) {
176188 try {
177189 for await ( const step of this . inst . run ( this . ctx ) ) {
178- let logStep ;
179- if ( typeof step === "string" || step instanceof String ) {
180- logStep = { msg : step }
181- } else {
182- logStep = step ;
190+ if ( step ) {
191+ this . wrappedLog ( step ) ;
183192 }
184- this . log ( { ...logStep , behavior : this . behaviorProps . id , siteSpecific : true } ) ;
185193 if ( this . paused ) {
186194 await this . paused ;
187195 }
188196 }
189- this . log ( { msg : "done!" , behavior : this . behaviorProps . id , siteSpecific : true } ) ;
197+ this . debug ( { msg : "done!" , behavior : this . behaviorProps . id } ) ;
190198 } catch ( e ) {
191- this . error ( { msg : e . toString ( ) , behavior : this . behaviorProps . id , siteSpecific : true } ) ;
199+ this . error ( { msg : e . toString ( ) , behavior : this . behaviorProps . id } ) ;
192200 }
193201 }
194202
0 commit comments