Re-writing the disabling of pino/logging - it seems that the pino logger is causing a variety of issues in the built CLI version - easier to offer an environment variable for backend-core which completely removes the logger.
This commit is contained in:
parent
ba47c60803
commit
552499b781
|
@ -154,6 +154,7 @@ const environment = {
|
||||||
? process.env.ENABLE_SSO_MAINTENANCE_MODE
|
? process.env.ENABLE_SSO_MAINTENANCE_MODE
|
||||||
: false,
|
: false,
|
||||||
VERSION: findVersion(),
|
VERSION: findVersion(),
|
||||||
|
DISABLE_PINO_LOGGER: process.env.DISABLE_PINO_LOGGER,
|
||||||
_set(key: any, value: any) {
|
_set(key: any, value: any) {
|
||||||
process.env[key] = value
|
process.env[key] = value
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export * as correlation from "./correlation/correlation"
|
export * as correlation from "./correlation/correlation"
|
||||||
export { logger, disableLogger } from "./pino/logger"
|
export { logger } from "./pino/logger"
|
||||||
export * from "./alerts"
|
export * from "./alerts"
|
||||||
|
|
||||||
// turn off or on context logging i.e. tenantId, appId etc
|
// turn off or on context logging i.e. tenantId, appId etc
|
||||||
|
|
|
@ -5,20 +5,11 @@ import * as correlation from "../correlation"
|
||||||
import { IdentityType } from "@budibase/types"
|
import { IdentityType } from "@budibase/types"
|
||||||
import { LOG_CONTEXT } from "../index"
|
import { LOG_CONTEXT } from "../index"
|
||||||
|
|
||||||
// CORE LOGGERS - for disabling
|
|
||||||
|
|
||||||
const BUILT_INS = {
|
|
||||||
log: console.log,
|
|
||||||
error: console.error,
|
|
||||||
info: console.info,
|
|
||||||
warn: console.warn,
|
|
||||||
trace: console.trace,
|
|
||||||
debug: console.debug,
|
|
||||||
}
|
|
||||||
|
|
||||||
// LOGGER
|
// LOGGER
|
||||||
|
|
||||||
const pinoOptions: LoggerOptions = {
|
let pinoInstance: pino.Logger | undefined
|
||||||
|
if (!env.DISABLE_PINO_LOGGER) {
|
||||||
|
const pinoOptions: LoggerOptions = {
|
||||||
level: env.LOG_LEVEL,
|
level: env.LOG_LEVEL,
|
||||||
formatters: {
|
formatters: {
|
||||||
level: label => {
|
level: label => {
|
||||||
|
@ -29,31 +20,22 @@ const pinoOptions: LoggerOptions = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env.isDev()) {
|
if (env.isDev()) {
|
||||||
pinoOptions.transport = {
|
pinoOptions.transport = {
|
||||||
target: "pino-pretty",
|
target: "pino-pretty",
|
||||||
options: {
|
options: {
|
||||||
singleLine: true,
|
singleLine: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const logger = pino(pinoOptions)
|
pinoInstance = pino(pinoOptions)
|
||||||
|
|
||||||
export function disableLogger() {
|
|
||||||
console.log = BUILT_INS.log
|
|
||||||
console.error = BUILT_INS.error
|
|
||||||
console.info = BUILT_INS.info
|
|
||||||
console.warn = BUILT_INS.warn
|
|
||||||
console.trace = BUILT_INS.trace
|
|
||||||
console.debug = BUILT_INS.debug
|
|
||||||
}
|
|
||||||
|
|
||||||
// CONSOLE OVERRIDES
|
// CONSOLE OVERRIDES
|
||||||
|
|
||||||
interface MergingObject {
|
interface MergingObject {
|
||||||
objects?: any[]
|
objects?: any[]
|
||||||
tenantId?: string
|
tenantId?: string
|
||||||
appId?: string
|
appId?: string
|
||||||
|
@ -61,25 +43,25 @@ interface MergingObject {
|
||||||
identityType?: IdentityType
|
identityType?: IdentityType
|
||||||
correlationId?: string
|
correlationId?: string
|
||||||
err?: Error
|
err?: Error
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPlainObject(obj: any) {
|
function isPlainObject(obj: any) {
|
||||||
return typeof obj === "object" && obj !== null && !(obj instanceof Error)
|
return typeof obj === "object" && obj !== null && !(obj instanceof Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isError(obj: any) {
|
function isError(obj: any) {
|
||||||
return obj instanceof Error
|
return obj instanceof Error
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMessage(obj: any) {
|
function isMessage(obj: any) {
|
||||||
return typeof obj === "string"
|
return typeof obj === "string"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backwards compatibility between console logging statements
|
* Backwards compatibility between console logging statements
|
||||||
* and pino logging requirements.
|
* and pino logging requirements.
|
||||||
*/
|
*/
|
||||||
function getLogParams(args: any[]): [MergingObject, string] {
|
function getLogParams(args: any[]): [MergingObject, string] {
|
||||||
let error = undefined
|
let error = undefined
|
||||||
let objects: any[] = []
|
let objects: any[] = []
|
||||||
let message = ""
|
let message = ""
|
||||||
|
@ -117,47 +99,47 @@ function getLogParams(args: any[]): [MergingObject, string] {
|
||||||
}
|
}
|
||||||
|
|
||||||
return [mergingObject, message]
|
return [mergingObject, message]
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log = (...arg: any[]) => {
|
console.log = (...arg: any[]) => {
|
||||||
const [obj, msg] = getLogParams(arg)
|
const [obj, msg] = getLogParams(arg)
|
||||||
logger.info(obj, msg)
|
pinoInstance?.info(obj, msg)
|
||||||
}
|
}
|
||||||
console.info = (...arg: any[]) => {
|
console.info = (...arg: any[]) => {
|
||||||
const [obj, msg] = getLogParams(arg)
|
const [obj, msg] = getLogParams(arg)
|
||||||
logger.info(obj, msg)
|
pinoInstance?.info(obj, msg)
|
||||||
}
|
}
|
||||||
console.warn = (...arg: any[]) => {
|
console.warn = (...arg: any[]) => {
|
||||||
const [obj, msg] = getLogParams(arg)
|
const [obj, msg] = getLogParams(arg)
|
||||||
logger.warn(obj, msg)
|
pinoInstance?.warn(obj, msg)
|
||||||
}
|
}
|
||||||
console.error = (...arg: any[]) => {
|
console.error = (...arg: any[]) => {
|
||||||
const [obj, msg] = getLogParams(arg)
|
const [obj, msg] = getLogParams(arg)
|
||||||
logger.error(obj, msg)
|
pinoInstance?.error(obj, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* custom trace impl - this resembles the node trace behaviour rather
|
* custom trace impl - this resembles the node trace behaviour rather
|
||||||
* than traditional trace logging
|
* than traditional trace logging
|
||||||
* @param arg
|
* @param arg
|
||||||
*/
|
*/
|
||||||
console.trace = (...arg: any[]) => {
|
console.trace = (...arg: any[]) => {
|
||||||
const [obj, msg] = getLogParams(arg)
|
const [obj, msg] = getLogParams(arg)
|
||||||
if (!obj.err) {
|
if (!obj.err) {
|
||||||
// to get stack trace
|
// to get stack trace
|
||||||
obj.err = new Error()
|
obj.err = new Error()
|
||||||
}
|
}
|
||||||
logger.trace(obj, msg)
|
pinoInstance?.trace(obj, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug = (...arg: any) => {
|
console.debug = (...arg: any) => {
|
||||||
const [obj, msg] = getLogParams(arg)
|
const [obj, msg] = getLogParams(arg)
|
||||||
logger.debug(obj, msg)
|
pinoInstance?.debug(obj, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONTEXT
|
// CONTEXT
|
||||||
|
|
||||||
const getTenantId = () => {
|
const getTenantId = () => {
|
||||||
let tenantId
|
let tenantId
|
||||||
try {
|
try {
|
||||||
tenantId = context.getTenantId()
|
tenantId = context.getTenantId()
|
||||||
|
@ -165,9 +147,9 @@ const getTenantId = () => {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
return tenantId
|
return tenantId
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAppId = () => {
|
const getAppId = () => {
|
||||||
let appId
|
let appId
|
||||||
try {
|
try {
|
||||||
appId = context.getAppId()
|
appId = context.getAppId()
|
||||||
|
@ -175,9 +157,9 @@ const getAppId = () => {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
return appId
|
return appId
|
||||||
}
|
}
|
||||||
|
|
||||||
const getIdentity = () => {
|
const getIdentity = () => {
|
||||||
let identity
|
let identity
|
||||||
try {
|
try {
|
||||||
identity = context.getIdentity()
|
identity = context.getIdentity()
|
||||||
|
@ -185,4 +167,7 @@ const getIdentity = () => {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
return identity
|
return identity
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const logger = pinoInstance
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
process.env.DISABLE_PINO_LOGGER = "1"
|
||||||
import "./prebuilds"
|
import "./prebuilds"
|
||||||
import "./environment"
|
import "./environment"
|
||||||
import { env, logging } from "@budibase/backend-core"
|
import { env } from "@budibase/backend-core"
|
||||||
logging.disableLogger()
|
|
||||||
import { getCommands } from "./options"
|
import { getCommands } from "./options"
|
||||||
import { Command } from "commander"
|
import { Command } from "commander"
|
||||||
import { getHelpDescription } from "./utils"
|
import { getHelpDescription } from "./utils"
|
||||||
|
|
Loading…
Reference in New Issue