Bit of a weird one. I'm fascinated with the context
object in Azure, although I have not been able to find the full source code for it.
When using it within Azure function apps, you can do both context.log
and context.log.error
. I'm trying to replicate this in a local mock like so:
let context = {
log(message){
console.log(message)
},
log: {
info: console.log,
error: console.error
}
}
But clearly the second log
property overrides the function so I can't do both context.log and context.log.error.
I also tried
let context = {
'log': console.log,
'log.error': console.error
}
But here, context.log.error
is undefined, however context['log.error']
works.
Eventually, I found one that does work:
let context = {
'log': console.log,
}
context.log['error'] = console.error
context.log['info'] = console.log
Which does do what i want:
context.log('message') // prints 'message'
context.log.error('message') // prints error 'message'
But I would like to understand why that last bit worked, and additionally, how I can declare all of it in one go instead of relying on context.log[error] = value