40 lines
947 B
PHP
40 lines
947 B
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
use phpcommon;
|
|
|
|
class GameLog
|
|
{
|
|
private static function writeStrToFile($filename, $str)
|
|
{
|
|
$fp = fopen($filename, 'a');
|
|
if (!$fp) {
|
|
return;
|
|
}
|
|
if (flock($fp, LOCK_EX)) {
|
|
fwrite($fp, date("Y-m-d H:i:s ",time()));
|
|
fwrite($fp, $str . "\n");
|
|
flock($fp, LOCK_UN);
|
|
}
|
|
fclose($fp);
|
|
}
|
|
|
|
private static function writeToLog($pro_name, $gameid, $str)
|
|
{
|
|
$log_dir = "/data/logs/$pro_name/$gameid/upload/";
|
|
$log_file_name_fmt = $log_dir . 'log_000%d_%s.log';
|
|
if (!is_dir($log_dir)) {
|
|
mkdir($log_dir, 0766, true);
|
|
}
|
|
|
|
$log_file_name = sprintf($log_file_name_fmt, posix_getppid(), date('YmdH'));
|
|
GameLog::writeStrToFile($log_file_name, $str);
|
|
}
|
|
|
|
public static function Log($content)
|
|
{
|
|
GameLog::writeToLog('game2004api', 2004, $content);
|
|
}
|
|
}
|