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 { budibaseTempDir } from "../objectStore"
|
||||
|
||||
const logsFileName = path.join(budibaseTempDir(), `budibase.logs`)
|
||||
const rollingFileName = `${logsFileName}.bak`
|
||||
const logsFileName = `budibase.logs`
|
||||
const budibaseLogsHistoryFileName = "budibase-logs-history.txt"
|
||||
|
||||
const logsPath = path.join(budibaseTempDir(), "systemlogs")
|
||||
|
||||
function getFullPath(fileName: string) {
|
||||
return path.join(logsPath, fileName)
|
||||
}
|
||||
|
||||
export function localFileDestination() {
|
||||
const outFile = rfs.createStream(logsFileName, {
|
||||
size: env.ROLLING_LOG_MAX_SIZE,
|
||||
})
|
||||
|
||||
outFile.on("rotation", () => {
|
||||
fs.copyFileSync(logsFileName, rollingFileName)
|
||||
path: logsPath,
|
||||
maxFiles: 1,
|
||||
immutable: true,
|
||||
history: "budibase-logs-history.txt",
|
||||
initialRotation: false,
|
||||
})
|
||||
|
||||
return outFile
|
||||
}
|
||||
|
||||
export function getLogReadStream() {
|
||||
const logsContent = fs.readFileSync(logsFileName)
|
||||
if (!fs.existsSync(rollingFileName)) {
|
||||
return logsContent
|
||||
const streams = []
|
||||
const historyFile = getFullPath(budibaseLogsHistoryFileName)
|
||||
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)
|
||||
const combinedContent = Buffer.concat([rollingContent, logsContent])
|
||||
streams.push(fs.readFileSync(getFullPath(logsFileName)))
|
||||
|
||||
const combinedContent = Buffer.concat(streams)
|
||||
return combinedContent
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue