public function traceLog(string $key = null, $message = null)
    {
        if ($this->trace_log_enabled) {
            if (is_array($message) || is_object($message)) {
                $text = print_r($message, true);
            } elseif ($message === null) {
                $text = "[null]";
            } elseif ($message === false) {
                $text = "[false]";
            } elseif ($message === true) {
                $text = "[true]";
            } else {
                $text = $message;
            }
            error_log("=== " . ($key !== null ? "$key: " : '') . $text);
        }

        if ($key === null) {
            if ($this->trace_log_buffer === null) {
                $this->trace_log_buffer = array();
            }
            if (array_key_exists(self::MESSAGES_STACK, $this->trace_log_buffer)) {
                $this->trace_log_buffer[self::MESSAGES_STACK][] = $message;
            } else {
                $this->trace_log_buffer[self::MESSAGES_STACK] = array($message);
            }
        } else {
            $this->trace_log_buffer[$key] = $message;
        }
    }