Skip to content

Commit 44fb10c

Browse files
committed
refactor(client): Refactor console logs to use logger utility
1 parent c5d5f29 commit 44fb10c

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/database/Client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logger from '../utils/logger';
12
import { ConnectionPool } from './ConnectionPool';
23
import { TablesService } from './service/Tables';
34
export class Client {
@@ -8,13 +9,13 @@ export class Client {
89
async initialize() {
910
await this._connectionPool.connect();
1011
const tablesService = new TablesService(this._connectionPool);
11-
console.log('Setting up initial tables...');
12+
logger.info('Setting up initial tables...');
1213
await tablesService.initialTables();
13-
console.log('Initial Tables Setup Completed.');
14+
logger.info('Initial Tables Setup Completed.');
1415

15-
console.log('Seeding tables...');
16+
logger.info('Seeding tables...');
1617
await tablesService.seedTables();
17-
console.log('Tables seeded successfully.');
18+
logger.info('Tables seeded successfully.');
1819
}
1920
getConnectionPool(): ConnectionPool {
2021
return this._connectionPool;

src/database/service/Tables.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ConnectionPool } from '../ConnectionPool';
33
import * as path from 'path';
44
import * as fs from 'fs/promises';
55
import Config from '../../config/index';
6+
import logger from '../../utils/logger';
67
export class TablesService {
78
constructor(private _connectionPool: ConnectionPool) {}
89
@Catch({
@@ -16,7 +17,7 @@ export class TablesService {
1617
const sqlFilePath = Config.environment === 'production' ? productionPath : path.join(__dirname, '..', './sql/Tables.sql');
1718
const sql = await fs.readFile(sqlFilePath, 'utf-8');
1819
await client.query(sql);
19-
console.log('Initial tables have been set up successfully.');
20+
logger.info('Initial tables have been set up successfully.');
2021
}
2122
@Catch({
2223
category: 'Database',
@@ -28,13 +29,13 @@ export class TablesService {
2829
const result = await client.query(`SELECT COUNT(*) FROM "User";`);
2930
const userCount = parseInt(result.rows[0].count, 10);
3031
if (userCount > 0) {
31-
console.log('The tables have already been seeded. Skipping seeding process.');
32+
logger.info('The tables have already been seeded. Skipping seeding process.');
3233
return; // Skip seeding if there's already data in the User table
3334
}
3435
const productionPath = path.join(process.cwd(), 'src', 'database', 'sql', 'seed', 'SeedDataTables.sql');
3536
const sqlFilePath = Config.environment === 'production' ? productionPath : path.join(__dirname, '..', './sql/seed/SeedDataTables.sql');
3637
const sql = await fs.readFile(sqlFilePath, 'utf-8');
3738
await client.query(sql);
38-
console.log('All tables have been seeded successfully.');
39+
logger.info('All tables have been seeded successfully.');
3940
}
4041
}

0 commit comments

Comments
 (0)