private static function debug_print($file, $level, $format, $data)
    {
        array_shift($data);
        foreach ($data as $k => $v) {
            if (is_string($v)) {
                $data[$k] = str_replace("\n", ' ', $v);
            } elseif ($v instanceof \Exception) {
                $data[$k] = $v->__toString();
            } elseif (!is_numeric($v)) {
                $data[$k] = str_replace("\n", " ", json_encode($v));
            }
        }

        $mtime = microtime(true);
        $time = 1000 * ($mtime - intval($mtime));

        $trace = debug_backtrace();
        $location = $trace[2]['function'];
        for ($n = 2; $n < sizeof($trace); $n++) {
            if (isset($trace[$n]['class'])) {
                $location = $trace[$n]['class'];
                break;
            }
        }

        $id = isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : getmypid();

        $msg = sizeof($data) ? vsprintf($format, $data) : $format;
        error_log(sprintf("[%s.%03d %s %s %s] %s\n", date('d.m.Y H:m:s'), $time, $id, $level, $location, $msg), 3, $file);
    }