Use native history
This commit is contained in:
parent
4b32c51924
commit
2585b73723
|
@ -5,28 +5,41 @@ import * as rfs from "rotating-file-stream"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { budibaseTempDir } from "../objectStore"
|
import { budibaseTempDir } from "../objectStore"
|
||||||
|
|
||||||
const logsFileName = path.join(budibaseTempDir(), `budibase.logs`)
|
const logsFileName = `budibase.logs`
|
||||||
const rollingFileName = `${logsFileName}.bak`
|
const budibaseLogsHistoryFileName = "budibase-logs-history.txt"
|
||||||
|
|
||||||
|
const logsPath = path.join(budibaseTempDir(), "systemlogs")
|
||||||
|
|
||||||
|
function getFullPath(fileName: string) {
|
||||||
|
return path.join(logsPath, fileName)
|
||||||
|
}
|
||||||
|
|
||||||
export function localFileDestination() {
|
export function localFileDestination() {
|
||||||
const outFile = rfs.createStream(logsFileName, {
|
const outFile = rfs.createStream(logsFileName, {
|
||||||
size: env.ROLLING_LOG_MAX_SIZE,
|
size: env.ROLLING_LOG_MAX_SIZE,
|
||||||
})
|
path: logsPath,
|
||||||
|
maxFiles: 1,
|
||||||
outFile.on("rotation", () => {
|
immutable: true,
|
||||||
fs.copyFileSync(logsFileName, rollingFileName)
|
history: "budibase-logs-history.txt",
|
||||||
|
initialRotation: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
return outFile
|
return outFile
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLogReadStream() {
|
export function getLogReadStream() {
|
||||||
const logsContent = fs.readFileSync(logsFileName)
|
const streams = []
|
||||||
if (!fs.existsSync(rollingFileName)) {
|
const historyFile = getFullPath(budibaseLogsHistoryFileName)
|
||||||
return logsContent
|
if (fs.existsSync(historyFile)) {
|
||||||
|
const fileContent = fs.readFileSync(historyFile, "utf-8")
|
||||||
|
const historyFiles = fileContent.split("\n")
|
||||||
|
for (const historyFile of historyFiles.filter(x => x)) {
|
||||||
|
streams.push(fs.readFileSync(historyFile))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rollingContent = fs.readFileSync(rollingFileName)
|
streams.push(fs.readFileSync(getFullPath(logsFileName)))
|
||||||
const combinedContent = Buffer.concat([rollingContent, logsContent])
|
|
||||||
|
const combinedContent = Buffer.concat(streams)
|
||||||
return combinedContent
|
return combinedContent
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue