1
0
Fork 0
mirror of synced 2024-07-15 19:25:55 +12:00

Merge pull request #10634 from Budibase/chore/automation-logging-updates-2

Supported named keys for json logged objects
This commit is contained in:
Rory Powell 2023-05-18 08:46:12 +01:00 committed by GitHub
commit 260a3e9c96
3 changed files with 53 additions and 11 deletions

View file

@ -94,12 +94,37 @@ if (!env.DISABLE_PINO_LOGGER) {
} }
} }
const mergingObject = { const mergingObject: any = {
objects: objects.length ? objects : undefined,
err: error, err: error,
...contextObject, ...contextObject,
} }
if (objects.length) {
// init generic data object for params supplied that don't have a
// '_logKey' field. This prints an object using argument index as the key
// e.g. { 0: {}, 1: {} }
const data: any = {}
let dataIndex = 0
for (let i = 0; i < objects.length; i++) {
const object = objects[i]
// the object has specified a log key
// use this instead of generic key
const logKey = object._logKey
if (logKey) {
delete object._logKey
mergingObject[logKey] = object
} else {
data[dataIndex] = object
dataIndex++
}
}
if (Object.keys(data).length) {
mergingObject.data = data
}
}
return [mergingObject, message] return [mergingObject, message]
} }

View file

@ -45,7 +45,8 @@ function getLogParams(
const message = `[BULL] ${eventType}=${event}` const message = `[BULL] ${eventType}=${event}`
const err = opts.error const err = opts.error
const data = { const bullLog = {
_logKey: "bull",
eventType, eventType,
event, event,
job: opts.job, job: opts.job,
@ -53,7 +54,17 @@ function getLogParams(
...extra, ...extra,
} }
return [message, err, data] let automationLog
if (opts.job?.data?.automation) {
automationLog = {
_logKey: "automation",
trigger: opts.job
? opts.job.data.automation.definition.trigger.event
: undefined,
}
}
return [message, err, bullLog, automationLog]
} }
enum BullEvent { enum BullEvent {

View file

@ -17,10 +17,16 @@ const CRON_STEP_ID = definitions.CRON.stepId
const Runner = new Thread(ThreadType.AUTOMATION) const Runner = new Thread(ThreadType.AUTOMATION)
function loggingArgs(job: AutomationJob) { function loggingArgs(job: AutomationJob) {
return { return [
jobId: job.id, {
trigger: job.data.automation.definition.trigger.event, _logKey: "automation",
} trigger: job.data.automation.definition.trigger.event,
},
{
_logKey: "bull",
jobId: job.id,
},
]
} }
export async function processEvent(job: AutomationJob) { export async function processEvent(job: AutomationJob) {
@ -29,16 +35,16 @@ export async function processEvent(job: AutomationJob) {
const task = async () => { const task = async () => {
try { try {
// need to actually await these so that an error can be captured properly // need to actually await these so that an error can be captured properly
console.log("automation running", loggingArgs(job)) console.log("automation running", ...loggingArgs(job))
const runFn = () => Runner.run(job) const runFn = () => Runner.run(job)
const result = await quotas.addAutomation(runFn, { const result = await quotas.addAutomation(runFn, {
automationId, automationId,
}) })
console.log("automation completed", loggingArgs(job)) console.log("automation completed", ...loggingArgs(job))
return result return result
} catch (err) { } catch (err) {
console.error(`automation was unable to run`, err, loggingArgs(job)) console.error(`automation was unable to run`, err, ...loggingArgs(job))
return { err } return { err }
} }
} }