My favorites | Sign in
Project Logo
                
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
<?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 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();
}
}
?>
Show details Hide details

Change log

r11 by spligak on Apr 08, 2008   Diff
Documentation and clean-up
Go to: 
Project members, sign in to write a code review

Older revisions

r9 by spligak on Apr 08, 2008   Diff
New constants and logging level
awareness
r8 by spligak on Apr 08, 2008   Diff
More documentation and a fleshed-out
logging mechanism
r6 by spligak on Apr 08, 2008   Diff
Basic documentation and License
All revisions of this file

File info

Size: 1285 bytes, 59 lines
Hosted by Google Code