-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsimple-logging-config.js
More file actions
46 lines (36 loc) · 1.27 KB
/
simple-logging-config.js
File metadata and controls
46 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict'
// Handle SIGPIPE gracefully when output is piped
process.on('SIGPIPE', () => {
process.exit(0)
})
const sql = require('../../lib/sql')
// Example 1: Enable trace logging for debugging
// This will show all JavaScript and C++ debug messages
sql.logger.setLogLevel(sql.LogLevel.TRACE)
sql.logger.setConsoleLogging(true)
// Example 2: Enable logging to a file
// sql.logger.setLogFile('/var/log/myapp/sql-trace.log')
// Example 3: Use pre-configured settings
// sql.logger.configureForDevelopment() // TRACE level, console enabled
// sql.logger.configureForProduction('/var/log/myapp') // ERROR level, file only
// sql.logger.configureForTesting() // SILENT level
// Example 4: Disable all logging (default for production)
// sql.logger.setLogLevel(sql.LogLevel.SILENT)
// Now all SQL operations will use the configured logging
const { TestEnv } = require('../../test/env/test-env')
const env = new TestEnv()
const connectionString = env.connectionString
sql.open(connectionString, (err, conn) => {
if (err) {
console.error('Connection failed:', err)
return
}
conn.query('SELECT 1 as test', (err, results) => {
if (err) {
console.error('Query failed:', err)
} else {
console.log('Query succeeded:', results)
}
conn.close()
})
})