Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Id: EbatNs_Logger.php,v 1.2 2008-05-02 15:04:05 carsten Exp $
3
// $Log: EbatNs_Logger.php,v $
4
// Revision 1.2  2008-05-02 15:04:05  carsten
5
// Initial, PHP5
6
//
7
//
8
class EbatNs_Logger
9
{
10
	// debugging options
11
	protected $debugXmlBeautify = true;
12
	protected $debugLogDestination = 'stdout';
13
	protected $debugSecureLogging = true;
14
	protected $debugHtml = true;
15
 
16
	function __construct($beautfyXml = false, $destination = 'stdout', $asHtml = true, $SecureLogging = true)
17
	{
18
		$this->debugLogDestination = $destination;
19
		$this->debugXmlBeautify = $beautfyXml;
20
		$this->debugHtml = $asHtml;
21
		$this->debugSecureLogging = $SecureLogging;
22
	}
23
 
24
	function log($msg, $subject = null)
25
	{
26
		if ($this->debugLogDestination)
27
		{
28
			if ($this->debugLogDestination == 'stdout')
29
			{
30
				if ($this->debugHtml)
31
				{
32
					print_r("<pre>");
33
					if ($subject)
34
						print_r("$subject :<br>");
35
					print_r(htmlentities($msg) . "\r\n");
36
					print_r("</pre>");
37
				}
38
				else
39
				{
40
					if ($subject)
41
						print_r($subject . ' : ' . "\r\n");
42
					print_r($msg . "\r\n");
43
				}
44
			}
45
			else
46
			{
47
				ob_start();
48
				echo date('r') . "\t" . $subject . "\t";
49
				print_r($msg);
50
				echo "\r\n";
51
				error_log(ob_get_clean(), 3, $this->debugLogDestination);
52
			}
53
		}
54
	}
55
 
56
	function logXml($xmlMsg, $subject = null)
57
	{
58
		if ($this->debugSecureLogging)
59
		{
60
			$xmlMsg = preg_replace("/<eBayAuthToken>.*<\/eBayAuthToken>/", "<eBayAuthToken>...</eBayAuthToken>", $xmlMsg);
61
			$xmlMsg = preg_replace("/<AuthCert>.*<\/AuthCert>/", "<AuthCert>...</AuthCert>", $xmlMsg);
62
		}
63
 
64
		if ($this->debugXmlBeautify)
65
		{
66
			if (is_object($xmlMsg))
67
				$this->log($xmlMsg);
68
			else
69
			{
70
				require_once 'XML/Beautifier.php';
71
				$xmlb = new XML_Beautifier();
72
				$this->log($xmlb->formatString($xmlMsg), $subject);
73
			}
74
 
75
			return;
76
		}
77
 
78
		$this->log($xmlMsg, $subject);
79
	}
80
}
81
 
82
class EbatNs_LoggerWire extends EbatNs_Logger
83
{
84
	protected $Request = '';
85
	protected $Response = '';
86
	function __construct()
87
	{
88
		parent::__construct(false, '', false, false);
89
	}
90
 
91
	function log($msg, $subject = null)
92
	{
93
		if ($subject == 'Request')
94
		{
95
			$this->Request = $msg;
96
		}
97
		else
98
		{
99
			if ($subject == 'Response' || $subject == 'ResponseRaw')
100
			{
101
			    $this->Response = $msg;
102
			}
103
		}
104
	}
105
 
106
	function getFullWireLog($beautifyRequest = true)
107
	{
108
		if ($beautifyRequest === true)
109
		{
110
			require_once 'XML/Beautifier.php';
111
			$xmlb = new XML_Beautifier();
112
			$this->Request = $xmlb->formatString($this->Request);
113
		}
114
 
115
		return $this->_RequestUrl .
116
			($this->debugHtml ? "<br>" : "\n") .
117
			($this->debugHtml ? htmlentities($this->Request) :  $this->Request) .
118
			($this->debugHtml ? "<br>" : "\n") .
119
			($this->debugHtml ? htmlentities($this->Response) : $this->Response);
120
	}
121
}
122
?>