-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogs.php
98 lines (86 loc) · 3.58 KB
/
Logs.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Created by PhpStorm.
* Author: Ufuk Özdemir
* Date: 2019-05-24
* Time: 16:40
*/
class Logs {
protected $CI;
static $folder;
static $year;
static $month;
static $day;
static $path_year;
static $path_month;
static $path_day;
static $base_url;
static $referer;
static $user_id;
static $user_name;
static $user_referer;
public function __construct() {
$this->CI =& get_instance();
$this->CI->load->library('session');
static::$folder = 'logs';
static::$year = date("Y");
static::$month = date("m");
static::$day = date("d.m.Y").'.json';
static::$path_year = APPPATH.static::$folder.DIRECTORY_SEPARATOR.static::$year;
static::$path_month = APPPATH.static::$folder.DIRECTORY_SEPARATOR.static::$year.DIRECTORY_SEPARATOR.static::$month;
static::$path_day = static::$path_month.DIRECTORY_SEPARATOR.static::$day;
static::$base_url = $this->CI->config->item('base_url');
static::$referer = $this->CI->input->server('HTTP_REFERER');
static::$user_id = $this->CI->session->user_id;
static::$user_name = $this->CI->session->user_fullname;
static::$user_referer = static::$base_url == static::$referer ? DIRECTORY_SEPARATOR : str_replace(static::$base_url, '', static::$referer);
}
public static function log_save($log_data) {
if (!file_exists(static::$path_year)) {
mkdir(static::$path_year, 0755);
}
if (!file_exists(static::$path_month)) {
mkdir(static::$path_month, 0755);
}
if (!file_exists(static::$path_day)) {
touch(static::$path_day);
}
$current_data = file_get_contents(static::$path_day);
$array_data = json_decode($current_data, true);
$array_data[] = $log_data;
$data_proccesed = json_encode($array_data, JSON_UNESCAPED_SLASHES);
file_put_contents(static::$path_day, $data_proccesed);
}
public static function json_data($process_type, $process_log) {
$json_data = array(
'user_id' => static::$user_id,
'user_name' => static::$user_name,
'process_type' => $process_type,
'process_log' => $process_log,
'process_time' => time(),
'process_referer' => static::$user_referer
);
return $json_data;
}
public static function other($log_message) {
$text = static::json_data(0, $log_message);
static::log_save($text);
}
public static function insert($log_message) {
$text = static::json_data(1, $log_message);
static::log_save($text);
}
public static function update($log_message) {
$text = static::json_data(2, $log_message);
static::log_save($text);
}
public static function delete($log_message) {
$text = static::json_data(3, $log_message);
static::log_save($text);
}
public static function view($log_message) {
$text = static::json_data(4, $log_message);
static::log_save($text);
}
}