title: Custom logging in laravel 5.6
body: <p>I am having the following problem, I need to create a custom logger for my application, the code is as follows:</p>
  
  <p>config/logging.php</p>
  
  <pre><code>    'channels' =&gt; [
      'stack' =&gt; [
          'driver' =&gt; 'stack',
          'channels' =&gt; ['slack', 'logentries', 'custom'],
      ],
      'logentries' =&gt; [
          'driver'  =&gt; 'monolog',
          'level' =&gt; 'info',
          'handler' =&gt; Monolog\Handler\SyslogUdpHandler::class,
          'handler_with' =&gt; [
              'host' =&gt; 'us.data.logs.insight.rapid7.com',
              'port' =&gt; '14211',
          ],
      ],
      'custom' =&gt; [
          'driver' =&gt; 'custom',
          'via' =&gt; App\Logging\MongoLogger::class,
          'level' =&gt; 'debug',
          'formatter' =&gt; 'default',
      ],
      'single' =&gt; [
          'driver' =&gt; 'single',
          'path' =&gt; storage_path('logs/laravel.log'),
          'level' =&gt; 'debug',
      ],
      'daily' =&gt; [
          'driver' =&gt; 'daily',
          'path' =&gt; storage_path('logs/laravel.log'),
          'level' =&gt; 'debug',
          'days' =&gt; 7,
      ],
      'slack' =&gt; [
          'driver' =&gt; 'slack',
          'url' =&gt; env('LOG_SLACK_WEBHOOK_URL'),
          'username' =&gt; 'Laravel Log',
          'emoji' =&gt; ':boom:',
          'level' =&gt; 'critical',
      ],
      'syslog' =&gt; [
          'driver' =&gt; 'syslog',
          'level' =&gt; 'debug',
      ],
      'errorlog' =&gt; [
          'driver' =&gt; 'errorlog',
          'level' =&gt; 'debug',
      ],
  ],
  </code></pre>
  
  <p>AfterMiddleWare.php</p>
  
  <pre><code>        $record = array(
          'tipo'           =&gt; 'debug',
          'url'            =&gt; Request::url(),
          'message'        =&gt; (string)'acesso_sistema',
          'datahora'       =&gt; \Carbon\Carbon::now(),
          'session_id'     =&gt; Session::getId(),
          'level'          =&gt; 'access_log',
          'so'             =&gt; BrowserDetect::platformName(),
          'mobile'         =&gt; BrowserDetect::isMobile(),
          'tempo_execucao' =&gt; (!empty($context['tempo_execucao'])) ? $context['tempo_execucao'] : 0,
          'dia_mes_ano'    =&gt; date('d/m/Y'),
          'usuario'        =&gt; $this-&gt;getUsuario(),
          'cliente'        =&gt; Session::get('cliente'),
          'ip_origem'      =&gt; Request::ip()
      );
  
      if(empty($record['datetime'])) {
          $record['datetime'] = $ts;
      }
  
      Log::debug(json_encode($record));
  
      return $response;
  </code></pre>
  
  <p>And the custom logger</p>
  
  <p>MongoLogger.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Logging;
  
  use Monolog\Handler\MongoDBHandler;
  use MongoDB\Client;
  use Monolog\Logger;
  
  
  class MongoLogger
  {
  
      /**
       * Customize the given logger instance.
       *
       * @param  \Illuminate\Log\Logger  $logger
       * @return void
       */
      public function __invoke($config)
      {
          die(print_r($config));
          $log = new Logger('debug');
          try {
              $log-&gt;pushHandler(new MongoDBHandler(new Client('mongodb://' . config('database.connections.mongodb.host') . ':' . config('database.connections.mongodb.port')), config('database.connections.mongodb.database'), 'logs', 'DEBUG'));
  
          } catch (\MongoConnectionException $e) {
  
              throw new \Exception('Cannot connect to Mongo - please check your server');
  
          }
          return $log;
      }
  }
  </code></pre>
  
  <p>I want the following to pass an additional parameter to the mongologger which would be the collection where I will insert the data;</p>
  
  <p>For example</p>
  
  <p>Log::debug(json_encode($record) , 'MYCOLLECTION'`</p>
  
  <p>but I'm not able to pass this parameter, how can I do this? </p>
  
  <p>thanks for helping</p>