Skip to content

Commit b420b75

Browse files
committedApr 3, 2025·
replaced logging
1 parent 9df1138 commit b420b75

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed
 

‎index.ts

+7-24
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,8 @@ import {
1111
import * as mysql2 from "mysql2/promise";
1212
import * as dotenv from "dotenv";
1313
import SqlParser, { AST } from 'node-sql-parser';
14+
import { log } from './utils/index.js';
1415

15-
// @INFO: Load environment variables from .env file
16-
dotenv.config()
17-
18-
// Logging configuration
19-
const ENABLE_LOGGING = process.env.ENABLE_LOGGING === '1'
20-
21-
type LogType = 'info' | 'error'
22-
23-
function log(type: LogType = 'info', ...args: any[]): void {
24-
if (!ENABLE_LOGGING) return
25-
26-
switch (type) {
27-
case 'info':
28-
console.info(...args)
29-
break
30-
case 'error':
31-
console.error(...args)
32-
break
33-
default:
34-
console.log(...args)
35-
}
36-
}
37-
38-
// Define interfaces for schema-specific permissions
3916
interface SchemaPermissions {
4017
[schema: string]: boolean
4118
}
@@ -49,6 +26,12 @@ export interface ColumnRow {
4926
data_type: string
5027
}
5128

29+
// @INFO: Load environment variables from .env file
30+
dotenv.config()
31+
32+
log('info', 'Starting MCP server...')
33+
34+
5235
// @INFO: Update the environment setup to ensure database is correctly set
5336
if (process.env.NODE_ENV === 'test' && !process.env.MYSQL_DB) {
5437
process.env.MYSQL_DB = 'mcp_test_db' // @INFO: Ensure we have a database name for tests

‎utils/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
type LogType = 'info' | 'error'
2+
3+
// @INFO: Enable logging if ENABLE_LOGGING is true
4+
const ENABLE_LOGGING = ["true", "1"].includes(process.env.ENABLE_LOGGING || 'false')
5+
6+
export function log(type: LogType = 'info', ...args: any[]): void {
7+
if (!ENABLE_LOGGING) return
8+
9+
switch (type) {
10+
case 'info':
11+
console.info(...args)
12+
break
13+
case 'error':
14+
console.error(...args)
15+
break
16+
default:
17+
console.log(...args)
18+
}
19+
}

0 commit comments

Comments
 (0)