Override Core Method correctly? #1460
Answered
by
remcoplasmeyer
rbartholomay
asked this question in
Help
-
Hi there, in the docu i find the example how to extend the core (Response) How can i override this method that is does exactly the same as before with an extra console.log for example (senseless i know) Bye, René |
Beta Was this translation helpful? Give feedback.
Answered by
remcoplasmeyer
Aug 14, 2020
Replies: 1 comment 1 reply
-
Maybe use IE, in a AppProvider: export default class AppProvider {
constructor (protected container: IocContract) {}
public async boot () {
const Logger = (await import('@ioc:Adonis/Core/Logger')).default
const oldInfo = Logger.info
const extendedLogger = function() {
oldInfo.apply(this, arguments)
console.log('Bar')
}
Logger.info = extendedLogger
Logger.info('Foo') // outputs Foo using original logger and Bar using console.log
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rbartholomay
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe use
apply
to extend the Logger's function?IE, in a AppProvider: