1
1
<?php
2
- class Log
2
+ class PDOLog
3
3
{
4
- private $ path = '/logs/ ' ;
5
- public function __construct ()
6
- {
7
- $ this ->path = dirname ( __FILE__ ) . $ this ->path ;
8
- }
9
-
10
- public function write ($ message , $ fileSalt )
11
- {
12
- $ date = new DateTime ();
13
- $ log = $ this ->path . $ date ->format ('Y-m-d ' ) . "- " . md5 ($ date ->format ('Y-m-d ' ) . $ fileSalt ) . ".txt " ;
14
- if (is_dir ($ this ->path )) {
15
- if (!file_exists ($ log )) {
16
- $ fh = fopen ($ log , 'a+ ' ) or die ("Fatal Error ! " );
17
- $ logcontent = "Time : " . $ date ->format ('H:i:s ' ) . "\r\n" . $ message . "\r\n" ;
18
- fwrite ($ fh , $ logcontent );
19
- fclose ($ fh );
20
- } else {
21
- $ this ->edit ($ log , $ date , $ message );
22
- }
23
- } else {
24
- if (mkdir ($ this ->path , 0777 ) === true ) {
25
- $ this ->write ($ message , $ fileSalt );
26
- }
27
- }
28
- }
29
- private function edit ($ log , $ date , $ message )
30
- {
31
- $ logcontent = "Time : " . $ date ->format ('H:i:s ' ) . "\r\n" . $ message . "\r\n\r\n" ;
32
- $ logcontent = $ logcontent . file_get_contents ($ log );
33
- file_put_contents ($ log , $ logcontent );
34
- }
4
+ private $ path = '/logs/ ' ;
5
+ public function __construct ()
6
+ {
7
+ $ this ->path = __DIR__ . $ this ->path ;
8
+ }
9
+
10
+ public function write ($ message , $ fileSalt )
11
+ {
12
+ $ date = new DateTime ();
13
+ $ log = $ this ->path . $ date ->format ('Y-m-d ' ) . "- " . md5 ($ date ->format ('Y-m-d ' ) . $ fileSalt ) . ".txt " ;
14
+ if (is_dir ($ this ->path )) {
15
+ if (!file_exists ($ log )) {
16
+ $ fh = fopen ($ log , 'a+ ' ) or die ("Fatal Error ! " );
17
+ $ logcontent = "Time : " . $ date ->format ('H:i:s ' ) . "\r\n" . $ message . "\r\n" ;
18
+ fwrite ($ fh , $ logcontent );
19
+ fclose ($ fh );
20
+ } else {
21
+ $ this ->edit ($ log , $ date , $ message );
22
+ }
23
+ } else {
24
+ if (mkdir ($ this ->path , 0777 ) === true ) {
25
+ $ this ->write ($ message , $ fileSalt );
26
+ }
27
+ }
28
+ }
29
+ private function edit ($ log ,DateTime $ date , $ message )
30
+ {
31
+ $ logcontent = "Time : " . $ date ->format ('H:i:s ' ) . "\r\n" . $ message . "\r\n\r\n" ;
32
+ $ logcontent = $ logcontent . file_get_contents ($ log );
33
+ file_put_contents ($ log , $ logcontent );
34
+ }
35
35
}
0 commit comments