/** * +---------------------------------------------------------- * 日志直接写入 * +---------------------------------------------------------- * @static * @access public * +---------------------------------------------------------- * * @param string $message 日志信息 * @param int|string $type 日志记录方式 * @param string $level 日志级别 * * @return void */ static function write($message, $type = 'common', $level = self::LOG_LEVEL_INFO) { global $_F; if (is_array($message)) { $message = json_encode($message); } $now = date("Y-m-d H:i:s"); $log_file_size = FConfig::get('logger.LOG_FILE_SIZE'); $log_file_size = $log_file_size ? $log_file_size : 1024000; $file_log_path = FConfig::get('logger.LOG_PATH'); $file_log_path = $file_log_path ? $file_log_path : F_APP_ROOT . 'data/logs/'; // $file_log_path = $file_log_path; if ($_F['run_in'] == 'shell') { $file_log_path .= $_F['run_in'] . '/'; } elseif (isset($_F['module'])) { $file_log_path .= $_F['module'] . '/'; } if ($type) { $file_log_path .= "{$type}/"; } $file_log_path .= date('Y-m-d') . '.log'; FFile::mkdir(dirname($file_log_path)); if (is_file($file_log_path) && floor($log_file_size) <= filesize($file_log_path)) { rename($file_log_path, str_replace(basename($file_log_path), date('Y-m-d.H_i_s') . '.log', $file_log_path)); } $write_content = "{$now}\t{$level}"; if ($_SERVER['REQUEST_URI']) { $write_content .= "\tURL:http:/" . "/{$_F['http_host']}{$_F['uri']}\t" . ($_F['refer'] ? "REFER:{$_F['refer']}" : ''); // } else { // $write_content .= "\t{$_F['run_in']}\t{$_F['module']}"; } $write_content .= "\t{$message}\r\n"; file_put_contents($file_log_path, $write_content, FILE_APPEND); }
public static function makeThumbPic($pic_file, $size = '100x100') { if (!file_exists($pic_file)) { return 'thumb_error_for_src_pic_not_exits'; } list($w, $h) = explode('x', $size); if (!$w || !$h) { throw new Exception("size 参数错误!必须是 100x100 这样的形式。"); } $thumb_file = "{$pic_file}.{$size}.jpg"; FFile::mkdir(dirname($thumb_file)); $fImage = new FImage(); $fImage->open($pic_file)->thumb($w, $h, FImage::THUMB_CENTER)->save($thumb_file); return true; }
/** * +---------------------------------------------------------- * 日志直接写入 * +---------------------------------------------------------- * @static * @access public * +---------------------------------------------------------- * * @param string $message 日志信息 * @param string $level 日志级别 * @param int|string $type 日志记录方式 * @param string $destination 写入目标 * @param string $extra 额外参数 * +---------------------------------------------------------- * * @return void +---------------------------------------------------------- */ static function write($message, $level = self::LOG_LEVEL_ERR, $type = '', $destination = '', $extra = '') { $now = date("Y-m-d H:i:s"); $type = $type ? $type : FConfig::get('logger.LOG_TYPE'); if (self::LOG_TYPE_FILE == $type) { // 文件方式记录日志 if (empty($destination)) { $destination = FConfig::get('logger.LOG_PATH') . date('Y-m-d') . '.log'; } FFile::mkdir(dirname($destination)); //检测日志文件大小,超过配置大小则备份日志文件重新生成 if (is_file($destination) && floor(FConfig::get('logger.LOG_FILE_SIZE')) <= filesize($destination)) { rename($destination, str_replace(basename($destination), date('Y-m-d.H_i_s') . '.log', $destination)); } } else { $destination = $destination ? $destination : ''; $extra = $extra ? $extra : FConfig::get('logger.LOG_EXTRA'); } error_log("{$now}\t" . $_SERVER['REQUEST_URI'] . "\t{$level}\t{$message}\r\n", $type, $destination, $extra); }