@@ -7,6 +7,7 @@ const { validateCurrency } = require('./models/Currency.js');
77const pool = require ( '../shared/database/src/postgresql.js' ) ;
88const create_table = require ( '../shared/database/src/create_table.js' ) ;
99const config = require ( '../shared/config/src/main.js' ) ( ) ;
10+ const logger = require ( '../shared/logger/src/main.js' ) ;
1011
1112const services = [ ] ;
1213const servicesDir = path . join ( __dirname , 'services' ) ;
@@ -33,16 +34,16 @@ async function main() {
3334 else if ( ! cron . isValidCron ( config [ 'schedule' ] , { alias : true } ) )
3435 throw new Error ( 'The crontab is invalid.' ) ;
3536
36- console . log ( 'Loading services...' ) ;
37+ logger . info ( 'Loading services...' ) ;
3738 config [ 'currency' ] [ 'services' ] [ 'enabled' ] . forEach ( ( serviceName ) => {
3839 const servicePath = path . join ( servicesDir , `${ serviceName } .js` ) ;
3940 if ( fs . existsSync ( servicePath ) ) {
4041 const serviceModule = require ( servicePath ) ;
4142
4243 services . push ( serviceModule ) ;
43- console . log ( `Service ${ serviceName } loaded successfully` ) ;
44+ logger . info ( `Service ${ serviceName } loaded successfully` ) ;
4445 } else {
45- console . error (
46+ logger . error (
4647 `Service file for ${ serviceName } not found at ${ servicePath } ` ,
4748 ) ;
4849 }
@@ -51,7 +52,7 @@ async function main() {
5152 await create_table ( ) ;
5253
5354 schedule . scheduleJob ( config [ 'schedule' ] , async ( ) => {
54- console . log ( 'Running scheduled task at:' , new Date ( ) ) ;
55+ logger . info ( 'Running scheduled task at:' , new Date ( ) ) ;
5556
5657 fiatFetched = false ;
5758 cryptoFetched = false ;
@@ -60,7 +61,7 @@ async function main() {
6061 const results = await srv . parseCurrencies ( ) ;
6162
6263 if ( Array . isArray ( results ) && results . length > 0 ) {
63- console . log (
64+ logger . info (
6465 `Data received from ${ srv . info . name || 'unknown service' } :` ,
6566 results . length ,
6667 'items' ,
@@ -69,14 +70,14 @@ async function main() {
6970 for ( const result of results ) {
7071 try {
7172 if ( srv . info . type === 'fiat' && fiatFetched ) {
72- console . log (
73+ logger . info (
7374 'Skipping fiat currency collection as data has already been fetched.' ,
7475 ) ;
7576 continue ;
7677 }
7778
7879 if ( srv . info . type === 'crypto' && cryptoFetched ) {
79- console . log (
80+ logger . info (
8081 'Skipping crypto currency collection as data has already been fetched.' ,
8182 ) ;
8283 continue ;
@@ -94,31 +95,31 @@ async function main() {
9495 currency . date ,
9596 ] ,
9697 ) ;
97- console . log (
98+ logger . info (
9899 `Inserted data for ${ currency . from_currency } -> ${ currency . conv_currency } , Rate: ${ rate } ` ,
99100 ) ;
100101 } catch ( validationError ) {
101- console . error ( 'Validation failed for data:' , result ) ;
102- console . error ( validationError ) ;
102+ logger . error ( 'Validation failed for data:' , result ) ;
103+ logger . error ( validationError ) ;
103104 }
104105 }
105106
106107 if ( srv . info . type === 'crypto' ) {
107108 cryptoFetched = true ;
108- console . log ( 'Crypto currency data fetched successfully.' ) ;
109+ logger . info ( 'Crypto currency data fetched successfully.' ) ;
109110 }
110111
111112 if ( srv . info . type === 'fiat' ) {
112113 fiatFetched = true ;
113- console . log ( 'Fiat currency data fetched successfully.' ) ;
114+ logger . info ( 'Fiat currency data fetched successfully.' ) ;
114115 }
115116 } else {
116- console . error ( 'Data not received for writing to the database.' ) ;
117+ logger . error ( 'Data not received for writing to the database.' ) ;
117118 }
118119 }
119120 } ) ;
120121
121- console . log ( `Scheduled task is running on schedule: ${ config [ 'schedule' ] } ` ) ;
122+ logger . info ( `Scheduled task is running on schedule: ${ config [ 'schedule' ] } ` ) ;
122123}
123124
124- main ( ) . catch ( console . error ) ;
125+ main ( ) . catch ( logger . error ) ;
0 commit comments