0

I know I can extend it as follows:

class MyLog extends Logs {
  ...
}

But, I don't want to do this as I have a plethora of Log::info() in my project in different places.

Can I extend Log::info() without making a new class MyLog?

Yaser Darzi
  • 1,480
  • 12
  • 24
Ahsan
  • 1,084
  • 2
  • 15
  • 28
  • extend how? what are you trying to do? `Log` is a facade, it just uses the `log` binding on the container – lagbox Nov 01 '19 at 07:36
  • https://stackoverflow.com/a/40615078/990164 is helpful, but it is with another class name. – Ahsan Nov 01 '19 at 07:49
  • I need to keep the usage same with Log::info class-name. – Ahsan Nov 01 '19 at 07:50
  • what are you trying to achieve ... why are you trying to extend this or change it? what is the functionality you need to change about it? – lagbox Nov 01 '19 at 07:51
  • I need to exclude some specific info from logged message. For example password, phone-number, api-token etc. – Ahsan Nov 01 '19 at 07:55

1 Answers1

0

Laravel is using Monolog for logging which you can add processors to that can manipulate the record before it gets sent to the different handlers for logging.

For now in the boot method of a Service Provider you could try:

\Log::pushProcessor(function ($record) {
    /*
    record array contains keys:
        message, context, level, level_name, channel, datetime, extra
     */

    // do what you need to return your filtered record
    return $record;        
});
lagbox
  • 48,571
  • 8
  • 72
  • 83