Logger.php 1.07 KB
Newer Older
ale's avatar
ale committed
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
<?php

	namespace WP_Piwik;

	abstract class Logger {
		
		private $loggerName = 'unnamed';
		private $loggerContent = array();
		private $startMicrotime = null;
		
		abstract function loggerOutput($loggerTime, $loggerMessage);

		public function __construct($loggerName) {
			$this->setName($loggerName);
			$this->setStartMicrotime(microtime(true));
			$this->log('Logging started -------------------------------');
		}
				
		public function __destruct() {
			$this->log('Logging finished ------------------------------');
		}
		
		public function log($loggerMessage) {
			$this->loggerOutput($this->getElapsedMicrotime(), $loggerMessage);
		}
		
		private function setName($loggerName) {
			$this->loggerName = $loggerName;
		}
		
		public function getName() {
			return $this->loggerName;
		}
		
		private function setStartMicrotime($startMicrotime) {
			$this->startMicrotime = $startMicrotime;
		}
		
		public function getStartMicrotime() {
			return $this->startMicrotime;
		}
		
		public function getElapsedMicrotime() {
			return microtime(true) - $this->getStartMicrotime();
		}
		
	}