Support setting object name for logged json objects
This commit is contained in:
parent
0595b4485e
commit
55ee94892a
|
@ -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]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue