Files.php
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 16/1/8
* Time: 11:36
*/
namespace Hood\Utils\Statistic;
class Files extends WorkerAbstract
{
static public function logs(Data $data)
{
self::write($data);
}
static public function write(Data $data)
{
$statistData = self::makeData($data);
$uri = str_replace('/', '_', $data->uri);
if (empty($uri)) $uri = 'system';
if (!is_dir($data->statistic_path)) {
umask(0);
mkdir($data->statistic_path, 0777, true);
}
file_put_contents($data->statistic_path . $uri . "." . date('Y-m-d') . '.log', $statistData, FILE_APPEND | LOCK_EX);
}
static public function error($errno, $errstr, $errfile, $errline)
{
$data = new Data();
$data->code = 500;
$data->type = 'error';
$data->data = array(
'errno' => $errno,
'errstr' => $errstr,
'errfile' => $errfile,
'errline' => $errline,
'backtrace' => debug_backtrace()
);
self::write($data);
}
static public function exception(\Exception $exception)
{
$data = new Data();
$data->code = 500;
$data->type = 'exception';
$data->data = array(
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTrace(),
'backtrace' => debug_backtrace()
);
self::write($data);
}
}