-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.php
93 lines (82 loc) · 1.8 KB
/
Logger.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
<?php if ( ! defined('DENY_ACCESS')) exit('403: No direct file access allowed');
/**
* A Bright CMS
*
* Open source, lightweight, web application framework and content management
* system in PHP.
*
* @package A Bright CMS
* @author Gabriel Liwerant
*/
/**
* Logger Class
*
* @subpackage core
* @author Gabriel Liwerant
*/
class Logger
{
/**
* Property for whether or not we are in log mode
*
* @var boolean $_is_mode_logging
*/
private $_is_mode_logging;
/**
* Upon contruction, set whether or not we are in logging mode.
*
* @param boolean $is_mode_logging
*/
public function __construct($is_mode_logging = true)
{
$this->_setIsModeLogging($is_mode_logging);
}
/**
* Setter for is mode logging property
*
* @param boolean $is_mode_logging
*
* @return object Logger
*/
private function _setIsModeLogging($is_mode_logging)
{
$this->_is_mode_logging = $is_mode_logging;
return $this;
}
/**
* Opens a file for logging and then writes a message to it.
*
* @param string $msg Message to write to log file
* @param string $type Type of message logged
* @param string $file_name Name of file to write log to
*
* @return boolean Return true or false to indicate success of logging
*/
public function writeLogToFile($msg, $type, $file_name)
{
if ($this->_is_mode_logging)
{
$file_path = LOGS_PATH . '/' . $file_name . '.log';
if ( ! $fh = @fopen($file_path, 'ab'))
{
return false;
}
else
{
$log_msg = '[' . date('m/d/Y h:i:s', time()) . '] ' . '[' . $type . '] ' . $msg . "\n";
flock($fh, LOCK_EX);
fwrite($fh, $log_msg);
flock($fh, LOCK_UN);
fclose($fh);
@chmod($file_path, 0666);
return true;
}
}
else
{
return false;
}
}
}
// End of Logger Class
/* EOF system/core/Logger.php */