code: public function flush($final = false)
      {
          $messages = $this->messages;
          // https://github.com/yiisoft/yii2/issues/5619
          // new messages could be logged while the existing ones are being handled by targets
          $this->messages = [];
          if ($this->dispatcher instanceof Dispatcher) {
              $this->dispatcher->dispatch($messages, $final);
          }
      }
docs: Flushes log messages from memory to targets.
  @param bool $final whether this is a final call during a request.