-
Notifications
You must be signed in to change notification settings - Fork 6
/
SMTP_Server_Log.php
73 lines (60 loc) · 1.69 KB
/
SMTP_Server_Log.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
<?php
/**
* SMTP_Server_Log
*
* @author Jason Johnson <jason@php-smtp.org>
* @copyright Copyright (c) 2008, Jason Johnson
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 1.0
* @package php-smtp
*/
class SMTP_Server_Log {
var $handle;
function SMTP_Server_Log() {
// If the log file exists and is writable, nothing else to do
if(file_exists(SMTP_LOG) && is_writable(SMTP_LOG))
return;
// Die if we could not create the log file directory
if(mkdir(dirname(SMTP_LOG), 0744, true) === false)
die("Could not create log file directory\n");
// Die if we could not create the log file
if(touch(SMTP_LOG) === false)
die("Could not create log file\n");
}
function open() {
$this->handle = fopen(SMTP_LOG, 'a');
}
function write($str) {
fwrite($this->handle, ($str."\n"));
}
function close() {
fclose($this->handle);
}
/**
* Log a message to the logfile specified in the constant SMTP_LOG
*
* @param int $level Takes SMTP_CRITICAL, SMTP_ERROR, SMTP_WARNING, SMTP_NOTICE, or SMTP_DEBUG
* @param string $msg The message to write to the logfile
*/
function msg($level, $msg) {
$this->open();
$log = false;
$time = date('j/M/Y:G:i:s O', time());
if($level <= SMTP_LOG_LEVEL) {
$log = true;
}
// Translate the int constant into a human-readable form
switch($level) {
case SMTP_CRITICAL: $level = 'CRITICAL'; break;
case SMTP_ERROR: $level = 'ERROR'; break;
case SMTP_WARNING: $level = 'WARNING'; break;
case SMTP_NOTICE: $level = 'NOTICE'; break;
case SMTP_DEBUG: $level = 'DEBUG'; break;
}
if($log) {
$this->write("[$level] - [$time] - $msg");
}
$this->close();
}
}
?>