Merge pull request #10634 from Budibase/chore/automation-logging-updates-2
Supported named keys for json logged objects
This commit is contained in:
commit
260a3e9c96
|
@ -94,12 +94,37 @@ if (!env.DISABLE_PINO_LOGGER) {
|
|||
}
|
||||
}
|
||||
|
||||
const mergingObject = {
|
||||
objects: objects.length ? objects : undefined,
|
||||
const mergingObject: any = {
|
||||
err: error,
|
||||
...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]
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ function getLogParams(
|
|||
const message = `[BULL] ${eventType}=${event}`
|
||||
const err = opts.error
|
||||
|
||||
const data = {
|
||||
const bullLog = {
|
||||
_logKey: "bull",
|
||||
eventType,
|
||||
event,
|
||||
job: opts.job,
|
||||
|
@ -53,7 +54,17 @@ function getLogParams(
|
|||
...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 {
|
||||
|
|
|
@ -17,10 +17,16 @@ const CRON_STEP_ID = definitions.CRON.stepId
|
|||
const Runner = new Thread(ThreadType.AUTOMATION)
|
||||
|
||||
function loggingArgs(job: AutomationJob) {
|
||||
return {
|
||||
jobId: job.id,
|
||||
return [
|
||||
{
|
||||
_logKey: "automation",
|
||||
trigger: job.data.automation.definition.trigger.event,
|
||||
}
|
||||
},
|
||||
{
|
||||
_logKey: "bull",
|
||||
jobId: job.id,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export async function processEvent(job: AutomationJob) {
|
||||
|
@ -29,16 +35,16 @@ export async function processEvent(job: AutomationJob) {
|
|||
const task = async () => {
|
||||
try {
|
||||
// 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 result = await quotas.addAutomation(runFn, {
|
||||
automationId,
|
||||
})
|
||||
console.log("automation completed", loggingArgs(job))
|
||||
console.log("automation completed", ...loggingArgs(job))
|
||||
return result
|
||||
} catch (err) {
|
||||
console.error(`automation was unable to run`, err, loggingArgs(job))
|
||||
console.error(`automation was unable to run`, err, ...loggingArgs(job))
|
||||
return { err }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue