Update log health check
This commit is contained in:
parent
e009481ac3
commit
efa325ed19
|
|
@ -1,11 +1,42 @@
|
|||
import type { HttpContext } from '@adonisjs/core/http'
|
||||
import axios from 'axios'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const linkWiki =
|
||||
process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test'
|
||||
const remoteUrl = process.env.ERP_URL || 'https://stage.nswteam.net'
|
||||
|
||||
export default class HealCheckController {
|
||||
private saveErrorLog(error: any) {
|
||||
try {
|
||||
const logsDir = path.join(process.cwd(), 'storage', 'health-check')
|
||||
|
||||
// Tạo thư mục nếu không tồn tại
|
||||
if (!fs.existsSync(logsDir)) {
|
||||
fs.mkdirSync(logsDir, { recursive: true })
|
||||
}
|
||||
|
||||
const timestamp = new Date().toISOString()
|
||||
const fileName = `healthcheck-error-${new Date().toISOString().split('T')[0]}.log`
|
||||
const filePath = path.join(logsDir, fileName)
|
||||
|
||||
const errorContent = `
|
||||
=== ERROR LOG ===
|
||||
Time: ${timestamp}
|
||||
Message: ${error?.message || 'Unknown error'}
|
||||
Status: ${error?.response?.status || 'N/A'}
|
||||
URL: ${error?.response?.config?.url || 'N/A'}
|
||||
Error Details: ${JSON.stringify(error?.response?.data || error, null, 2)}
|
||||
---
|
||||
`
|
||||
|
||||
fs.appendFileSync(filePath, errorContent)
|
||||
console.log(`Error logged to: ${filePath}`)
|
||||
} catch (logError) {
|
||||
console.error('Failed to save error log:', logError)
|
||||
}
|
||||
}
|
||||
// GET /health-check
|
||||
async check({ }: HttpContext) {
|
||||
try {
|
||||
|
|
@ -80,6 +111,9 @@ export default class HealCheckController {
|
|||
],
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Lưu log lỗi
|
||||
this.saveErrorLog(error)
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: [
|
||||
|
|
|
|||
Loading…
Reference in New Issue