protected static function buildMessage(
        /*# string */ $template,
        array $arguments
    )/*# : string */ {
        // use formatter
        if (self::hasFormatter()) {
            return self::getFormatter()
                    ->formatMessage($template, $arguments);

        // default is vsprintf()
        } else {
            // make sure arguments are all strings
            array_walk($arguments, function (&$value) {
                $value = is_scalar($value) ? (string) $value :
                    substr(print_r($value, true), 0, 50);
            });

            // make sure '%s' count in $template is same as size of $arguments
            $count = substr_count($template, '%s');
            $size  = sizeof($arguments);
            if ($count > $size) {
                $arguments = $arguments + array_fill($size, $count - $size, '');
            } else {
                $template .= str_repeat(' %s', $size - $count);
            }
            return vsprintf($template, $arguments);
        }
    }