1
- import { logUtils } from '@0x/ utils' ;
1
+ import { logger } from '../../ utils/logger ' ;
2
2
import { Connection } from 'typeorm' ;
3
3
4
4
import { FIRST_SEARCH_BLOCK , MAX_BLOCKS_TO_SEARCH , START_BLOCK_OFFSET } from '../../config' ;
@@ -17,16 +17,18 @@ export class PullAndSaveEvents {
17
17
const startBlock = await this . _getStartBlockAsync ( eventName , connection , latestBlockWithOffset ) ;
18
18
const endBlock = Math . min ( latestBlockWithOffset , startBlock + ( MAX_BLOCKS_TO_SEARCH - 1 ) ) ;
19
19
20
- logUtils . log ( `Searching for ${ eventName } between blocks ${ startBlock } and ${ endBlock } `) ;
20
+ logger . child ( { eventName, startBlock , endBlock } ) . info ( `Searching for events `) ;
21
21
const eventLogs = await getterFunction ( startBlock , endBlock ) ;
22
22
23
23
if ( eventLogs === null ) {
24
- logUtils . log ( `Encountered an error searching for ${ eventName } events. Waiting until next iteration.` ) ;
24
+ logger
25
+ . child ( { eventName } )
26
+ . info ( `Encountered an error searching for events. Waiting until next iteration.` ) ;
25
27
} else {
26
28
const parsedEventLogs = eventLogs . map ( log => parser ( log ) ) ;
27
29
const lastBlockProcessed : LastBlockProcessed = await this . _lastBlockProcessedAsync ( eventName , endBlock ) ;
28
30
29
- logUtils . log ( `saving ${ parsedEventLogs . length } ${ eventName } events`) ;
31
+ logger . child ( { count : parsedEventLogs . length , eventName } ) . info ( `Saving events`) ;
30
32
31
33
await this . _deleteOverlapAndSaveAsync < EVENT > (
32
34
connection ,
@@ -56,7 +58,7 @@ export class PullAndSaveEvents {
56
58
`SELECT last_processed_block_number FROM events.last_block_processed WHERE event_name = '${ eventName } '` ,
57
59
) ;
58
60
59
- logUtils . log ( queryResult ) ;
61
+ logger . child ( { ... queryResult , eventName } ) . info ( `Last processed block number for ${ eventName } ` ) ;
60
62
const lastKnownBlock = queryResult [ 0 ] || { last_processed_block_number : FIRST_SEARCH_BLOCK } ;
61
63
62
64
return Math . min (
@@ -89,7 +91,7 @@ export class PullAndSaveEvents {
89
91
// commit transaction now:
90
92
await queryRunner . commitTransaction ( ) ;
91
93
} catch ( err ) {
92
- logUtils . log ( err ) ;
94
+ logger . error ( err ) ;
93
95
// since we have errors lets rollback changes we made
94
96
await queryRunner . rollbackTransaction ( ) ;
95
97
} finally {
0 commit comments