Extract code

This commit is contained in:
Adria Navarro 2023-07-05 16:57:00 +02:00
parent e351a77f75
commit 580985c7be
2 changed files with 22 additions and 19 deletions

View File

@ -0,0 +1,20 @@
import fs from "fs"
import path from "path"
import * as rfs from "rotating-file-stream"
import { env } from "process"
import { budibaseTempDir } from "src/objectStore"
export function localFileDestination() {
const fileName = path.join(budibaseTempDir(), `budibase.logs`)
const outFile = rfs.createStream(fileName, {
size: env.ROLLING_LOG_MAX_SIZE,
teeToStdout: true,
})
outFile.on("rotation", () => {
fs.copyFileSync(fileName, `${fileName}.bak`)
})
return outFile
}

View File

@ -1,7 +1,5 @@
import pino, { LoggerOptions } from "pino"
import path from "path"
import fs from "fs"
import * as rfs from "rotating-file-stream"
import pinoPretty from "pino-pretty"
import { IdentityType } from "@budibase/types"
@ -10,8 +8,7 @@ import * as context from "../../context"
import * as correlation from "../correlation"
import { LOG_CONTEXT } from "../index"
import { budibaseTempDir } from "../../objectStore"
import pinoPretty from "pino-pretty"
import { localFileDestination } from "../localLogging"
// LOGGER
@ -71,20 +68,6 @@ if (!env.DISABLE_PINO_LOGGER) {
return typeof obj === "string"
}
function localFileDestination() {
const fileName = path.join(budibaseTempDir(), `budibase.logs`)
const outFile = rfs.createStream(fileName, {
size: env.ROLLING_LOG_MAX_SIZE,
teeToStdout: true,
})
outFile.on("rotation", () => {
fs.copyFileSync(fileName, `${fileName}.bak`)
})
return outFile
}
/**
* Backwards compatibility between console logging statements
* and pino logging requirements.