public function flushTo(OutputWriter $outputWriter)
    {
        if ($outputWriter === $this) {
            throw new LogicException('Operation not allowed');
        }
    
        $minLevel = $outputWriter->getLevel();
        
        while (!empty($this->buffer)) {
            $item = array_shift($this->buffer);
    
            if ($item['level'] < $minLevel) {
                continue;
            }
            
            switch ($item['level']) {
                case OutputLevel::ERROR:
                    $outputWriter->error($item['message'], $item['newLine']);
                break;
                case OutputLevel::NORMAL:
                    $outputWriter->normal($item['message'], $item['newLine']);
                break;
                case OutputLevel::VERBOSE:
                    $outputWriter->verbose($item['message'], $item['newLine']);
                break;
                case OutputLevel::VERY_VERBOSE:
                    $outputWriter->veryVerb($item['message'], $item['newLine']);
                break;
                case OutputLevel::DEBUG:
                    $outputWriter->debug($item['message'], $item['newLine']);
                break;
                default:
                    throw new UnexpectedValueException('Unexpected value of level');
            }
        }
    }