@@ -12,6 +12,7 @@ import {
1212 NetworkStatsEvent
1313} from './websocket-types'
1414import { blockCache } from './cache'
15+ import { logger } from './logger'
1516
1617export class BlockchainMonitor {
1718 private wsManager : WebSocketManager
@@ -47,24 +48,24 @@ export class BlockchainMonitor {
4748 } )
4849 } )
4950
50- console . log ( '[BlockchainMonitor] Initialized with config:' , this . config )
51+ logger . debug ( '[BlockchainMonitor] Initialized with config:' , this . config )
5152 }
5253
5354 /**
5455 * Start monitoring blockchain for all configured networks
5556 */
5657 async start ( ) : Promise < void > {
5758 if ( this . isRunning ) {
58- console . log ( '[BlockchainMonitor] Already running' )
59+ logger . debug ( '[BlockchainMonitor] Already running' )
5960 return
6061 }
6162
6263 if ( ! this . config . enabled ) {
63- console . log ( '[BlockchainMonitor] WebSocket disabled, not starting' )
64+ logger . debug ( '[BlockchainMonitor] WebSocket disabled, not starting' )
6465 return
6566 }
6667
67- console . log ( '[BlockchainMonitor] Starting monitor...' )
68+ logger . debug ( '[BlockchainMonitor] Starting monitor...' )
6869 this . isRunning = true
6970
7071 // Initialize states for all networks
@@ -86,7 +87,7 @@ export class BlockchainMonitor {
8687 await this . pollAllNetworks ( )
8788 await this . pollNetworkStats ( )
8889
89- console . log ( '[BlockchainMonitor] Monitor started successfully' )
90+ logger . info ( '[BlockchainMonitor] Monitor started successfully' )
9091 }
9192
9293 /**
@@ -97,7 +98,7 @@ export class BlockchainMonitor {
9798 return
9899 }
99100
100- console . log ( '[BlockchainMonitor] Stopping monitor...' )
101+ logger . debug ( '[BlockchainMonitor] Stopping monitor...' )
101102 this . isRunning = false
102103
103104 if ( this . pollInterval ) {
@@ -110,15 +111,15 @@ export class BlockchainMonitor {
110111 this . statsInterval = null
111112 }
112113
113- console . log ( '[BlockchainMonitor] Monitor stopped' )
114+ logger . info ( '[BlockchainMonitor] Monitor stopped' )
114115 }
115116
116117 /**
117118 * Initialize network state
118119 */
119120 private async initializeNetworkState ( network : NetworkType ) : Promise < void > {
120121 try {
121- console . log ( `[BlockchainMonitor] Initializing ${ network } state...` )
122+ logger . debug ( `[BlockchainMonitor] Initializing ${ network } state...` )
122123
123124 const blockCount = await blockCache . getBlockCount ( network )
124125 const block = await blockCache . getBlock ( blockCount , network , true )
@@ -133,7 +134,7 @@ export class BlockchainMonitor {
133134 state . lastUpdate = new Date ( )
134135 }
135136
136- console . log ( `[BlockchainMonitor] ${ network } initialized: Block ${ blockCount } ` )
137+ logger . debug ( `[BlockchainMonitor] ${ network } initialized: Block ${ blockCount } ` )
137138 } catch ( error ) {
138139 console . error ( `[BlockchainMonitor] Error initializing ${ network } :` , error )
139140 }
@@ -162,7 +163,7 @@ export class BlockchainMonitor {
162163 const newBlockCount = await blockCache . getBlockCount ( network )
163164
164165 if ( newBlockCount > state . blockHeight ) {
165- console . log ( `[BlockchainMonitor] ${ network } : New blocks detected (${ state . blockHeight } -> ${ newBlockCount } )` )
166+ logger . debug ( `[BlockchainMonitor] ${ network } : New blocks detected (${ state . blockHeight } -> ${ newBlockCount } )` )
166167
167168 // Fetch new blocks
168169 for ( let height = state . blockHeight + 1 ; height <= newBlockCount ; height ++ ) {
@@ -207,7 +208,7 @@ export class BlockchainMonitor {
207208 state . blockHash = block . hash
208209 }
209210
210- console . log ( `[BlockchainMonitor] ${ network } : Broadcasting new block ${ height } (${ block . hash } )` )
211+ logger . debug ( `[BlockchainMonitor] ${ network } : Broadcasting new block ${ height } (${ block . hash } )` )
211212
212213 // Broadcast new block event
213214 const newBlockEvent : NewBlockEvent = {
@@ -249,7 +250,7 @@ export class BlockchainMonitor {
249250 mempoolInfo &&
250251 ( mempoolInfo . size !== state . mempoolSize || mempoolInfo . bytes !== state . mempoolBytes )
251252 ) {
252- console . log ( `[BlockchainMonitor] ${ network } : Mempool changed (${ state . mempoolSize } -> ${ mempoolInfo . size } tx)` )
253+ logger . debug ( `[BlockchainMonitor] ${ network } : Mempool changed (${ state . mempoolSize } -> ${ mempoolInfo . size } tx)` )
253254
254255 state . mempoolSize = mempoolInfo . size
255256 state . mempoolBytes = mempoolInfo . bytes
@@ -326,7 +327,7 @@ export class BlockchainMonitor {
326327 }
327328 this . wsManager . broadcast ( statsEvent , network )
328329
329- console . log ( `[BlockchainMonitor] ${ network } : Broadcasted network stats update` )
330+ logger . debug ( `[BlockchainMonitor] ${ network } : Broadcasted network stats update` )
330331 }
331332 } catch ( error ) {
332333 console . error ( `[BlockchainMonitor] Error polling network stats for ${ network } :` , error )
0 commit comments