Rotate logs
This commit is contained in:
parent
d33663f5ac
commit
ff67df8e79
|
@ -51,6 +51,7 @@
|
||||||
"pouchdb": "7.3.0",
|
"pouchdb": "7.3.0",
|
||||||
"pouchdb-find": "7.2.2",
|
"pouchdb-find": "7.2.2",
|
||||||
"redlock": "4.2.0",
|
"redlock": "4.2.0",
|
||||||
|
"rotating-file-stream": "3.1.0",
|
||||||
"sanitize-s3-objectkey": "0.0.1",
|
"sanitize-s3-objectkey": "0.0.1",
|
||||||
"semver": "7.3.7",
|
"semver": "7.3.7",
|
||||||
"tar-fs": "2.1.1",
|
"tar-fs": "2.1.1",
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import env from "../../environment"
|
|
||||||
import pino, { LoggerOptions } from "pino"
|
import pino, { LoggerOptions } from "pino"
|
||||||
|
import path from "path"
|
||||||
|
import fs from "fs"
|
||||||
|
import * as rfs from "rotating-file-stream"
|
||||||
|
|
||||||
|
import { IdentityType } from "@budibase/types"
|
||||||
|
|
||||||
|
import env from "../../environment"
|
||||||
import * as context from "../../context"
|
import * as context from "../../context"
|
||||||
import * as correlation from "../correlation"
|
import * as correlation from "../correlation"
|
||||||
import { IdentityType } from "@budibase/types"
|
|
||||||
import { LOG_CONTEXT } from "../index"
|
import { LOG_CONTEXT } from "../index"
|
||||||
|
|
||||||
import path from "path"
|
|
||||||
import { budibaseTempDir } from "../../objectStore"
|
import { budibaseTempDir } from "../../objectStore"
|
||||||
|
import environment from "../../environment"
|
||||||
|
|
||||||
// LOGGER
|
// LOGGER
|
||||||
|
|
||||||
|
@ -25,7 +30,8 @@ if (!env.DISABLE_PINO_LOGGER) {
|
||||||
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env.isDev()) {
|
let outFile: rfs.RotatingFileStream | undefined
|
||||||
|
if (!env.isDev()) {
|
||||||
pinoOptions.transport = {
|
pinoOptions.transport = {
|
||||||
target: "pino-pretty",
|
target: "pino-pretty",
|
||||||
options: {
|
options: {
|
||||||
|
@ -33,15 +39,23 @@ if (!env.DISABLE_PINO_LOGGER) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pinoOptions.transport = {
|
const fileName = path.join(
|
||||||
target: "pino/file",
|
budibaseTempDir(),
|
||||||
options: {
|
"logs",
|
||||||
destination: path.join(budibaseTempDir(), "pino.logs"),
|
`${environment.SERVICE_NAME}.logs`
|
||||||
},
|
)
|
||||||
}
|
outFile = rfs.createStream(fileName, {
|
||||||
|
size: "10M",
|
||||||
|
|
||||||
|
teeToStdout: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
outFile.on("rotation", () => {
|
||||||
|
fs.copyFileSync(fileName, `${fileName}.bak`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pinoInstance = pino(pinoOptions)
|
pinoInstance = outFile ? pino(pinoOptions, outFile) : pino(pinoOptions)
|
||||||
|
|
||||||
// CONSOLE OVERRIDES
|
// CONSOLE OVERRIDES
|
||||||
|
|
||||||
|
|
|
@ -23197,6 +23197,11 @@ rollup@^3.18.0:
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
fsevents "~2.3.2"
|
fsevents "~2.3.2"
|
||||||
|
|
||||||
|
rotating-file-stream@3.1.0:
|
||||||
|
version "3.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/rotating-file-stream/-/rotating-file-stream-3.1.0.tgz#6cf50e1671de82a396de6d31d39a6f2445f45fba"
|
||||||
|
integrity sha512-TkMF6cP1/QDcon9D71mjxHoflNuznNOrY5JJQfuxkKklZRmoow/lWBLNxXVjb6KcjAU8BDCV145buLgOx9Px1Q==
|
||||||
|
|
||||||
rrweb-cssom@^0.6.0:
|
rrweb-cssom@^0.6.0:
|
||||||
version "0.6.0"
|
version "0.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz#ed298055b97cbddcdeb278f904857629dec5e0e1"
|
resolved "https://registry.yarnpkg.com/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz#ed298055b97cbddcdeb278f904857629dec5e0e1"
|
||||||
|
|
Loading…
Reference in New Issue