Skip to content

Override Core Method correctly? #1460

Discussion options

You must be logged in to vote

Maybe use apply to extend the Logger's function?

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
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rbartholomay
Comment options

Answer selected by rbartholomay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants