protected function openSink()
    {
        if (!$this->uri) {
            throw new \LogicException(
                'Missing stream uri, the stream can not be opened.'
            );
        }
        $this->error = null;
        set_error_handler(array($this, 'errorTrap'));

        if (substr($this->uri, 0, 4) === 'udp:') {
            $parsed = parse_url($this->uri);
            if (!isset($parsed['host'])) {
                throw new \UnexpectedValueException(sprintf(
                    'Udp transport "%s" must specify a host', $this->uri
                ));
            }
            if (!isset($parsed['port'])) {
                throw new \UnexpectedValueException(sprintf(
                    'Udp transport "%s" must specify a port', $this->uri
                ));
            }

            $this->prefix = '';
            if (isset($parsed['path'])) {
                $this->prefix = ltrim($parsed['path'], '/');
            }

            $this->writer = new UdpWriter($parsed['host'], $parsed['port']);
        } else {
            $this->writer = new StreamWriter($this->uri);
        }
        restore_error_handler();

        if ($this->error !== null) {
            $this->writer = null;
            throw new \UnexpectedValueException(sprintf(
                'The stream or file "%s" could not be opened: %s',
                $this->uri, $this->error
            ));
        }
    }