-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.php
More file actions
79 lines (68 loc) · 1.53 KB
/
Copy pathLog.php
File metadata and controls
79 lines (68 loc) · 1.53 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Created by JetBrains PhpStorm.
* User: mathieu.savy
* Date: 17/05/13
* Time: 11:41
* To change this template use File | Settings | File Templates.
*/
namespace Lib;
class Log
{
private static $instance;
private $file;
private static function getInstance()
{
if (self::$instance == null)
{
self::$instance = new Log();
if (self::$instance->file)
{
fwrite(self::$instance->file, "\n====== ");
fwrite(self::$instance->file, "Starting execution ");
fwrite(self::$instance->file, "======\n");
fwrite(self::$instance->file, "micro-muffin v" . LIB_VERSION_NUMBER . "\n");
}
}
return self::$instance;
}
private function __construct()
{
$sDirPath = __DIR__ . "/../log";
$sFilePath = $sDirPath . "/real-time.log";
if (is_writable($sDirPath))
{
if (!file_exists($sFilePath) || is_writable($sFilePath))
$this->file = fopen($sFilePath, "a");
else
$this->file = fopen('0-' . $sFilePath, 'a');
}
}
public function __destruct()
{
if ($this->file)
fclose($this->file);
}
/**
* @param $string
*/
public static function write($string)
{
$instance = self::getInstance();
if ($instance->file)
{
$date = date("d/m H:i:s");
fwrite($instance->file, "[" . $date . "]" . $string . "\n");
}
}
/**
* @param mixed $source
* @return string
*/
public static function dumpInVar($source)
{
ob_start();
var_export($source);
return ob_get_clean();
}
}