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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<?php /*____________________________________________________________
* @ description : ·Î±× »ç¿ëÀ» À§ÇÑ Å¬·¡½º * @ name : NicepayLiteLog.php * @ auther : NICEPAY I&T (tech@nicepay.co.kr) * @ date : * @ modify 2013.05.24 Update Log *____________________________________________________________ */ class NICELog { var $handle; var $type; var $log; var $debug_mode; var $array_key; var $debug_msg; var $starttime; var $debug; function NICELog($mode, $type ) { $this->log = "true"; $this->debug_msg = array( "", "CRITICAL", "ERROR", "NOTICE", "4", "INFO", "6", "DEBUG", "8" ); $this->debug_mode = $mode; $this->type = $type; $this->starttime= $this->GetMicroTime(); $debug = 5;
} function StartLog($dir) { $logfile = $dir. "/".$this->type."_".date("ymd").".log"; $this->handle = fopen( $logfile, "a+" ); if( !$this->handle ) { return false; } if($this->debug_mode != "INFO"){ $this->WriteLog( "START NICEPAY TX 1.0 (OS:".php_uname('s').php_uname('r').",PHP:".phpversion()."))" ); } return true; } function WriteLog($data) { if( !$this->handle || $this->log == "false" ) return; $pfx = " [" . date("Y-m-d H:i:s") . "] <" . getmypid() . "> "; fwrite( $this->handle, $pfx . $data . "\r\n" ); } function CloseNiceLog($msg){ $laptime=$this->GetMicroTime()-$this->starttime; $this->WriteLog( "END ".$this->type." ".$msg ." Laptime:[".round($laptime,3)."sec]" ); $this->WriteLog("===============================================================" ); fclose( $this->handle ); }
function WriteArrayLog($data) { if( !$this->handle || $this->log == "false" ) return; $pfx = $this->debug_msg[$debug]." [" . date("Y-m-d H:i:s") . "] <" . getmypid() . "> "; $this->printArray($data,$pfx); fflush( $this->handle ); }
function printArray($array, $pfx=''){ if(!empty($array)){ if (is_array($array)){ foreach ($array as $key => $val){ if( $key == "CardNo" && strlen($val)>14){ fwrite( $this->handle, $pfx . $key . ":[" .substr($val,0,12)."****" . "]\r\n"); }else if( $key == "CardPw" && strlen($val)==2){ fwrite( $this->handle, $pfx . $key . ":[" ."**" . "]\r\n"); }else{ fwrite( $this->handle, $pfx . $key . ":[" . $val . "]\r\n"); } if(is_array($val)){ $this->printArray($value, $pfx.' '); } } } } }
function Base64Encode( $str ) { return substr(chunk_split(base64_encode( $str ),64,"\n"),0,-1)."\n"; } function GetMicroTime() { list($usec, $sec) = explode(" ", microtime(true)); return (float)$usec + (float)$sec; } function SetTimestamp() { $m = explode(' ',microtime()); list($totalSeconds, $extraMilliseconds) = array($m[1], (int)round($m[0]*1000,3)); return date("Y-m-d H:i:s", $totalSeconds) . ":$extraMilliseconds"; } function SetTimestamp1() { $m = explode(' ',microtime()); list($totalSeconds, $extraMilliseconds) = array($m[1], (int)round($m[0]*10000,4)); return date("ymdHis", $totalSeconds) . "$extraMilliseconds"; }
}
?>
|