PluginProbe
Tracking Code Manager / 1.11.8
Tracking Code Manager v1.11.8
2.8.0 2.7.0 trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 All 29 releases
tracking-code-manager / includes / classes / utils / Logger.php
Logger.php
83 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) exit;
5
6 class TCMP_Logger {
7 private $name;
8 private $context=array();
9
10 public function __construct($name='TCMP') {
11 if($name=='') $name='TCMP';
12 $this->name=$name;
13 }
14
15 public function pushContext($context) {
16 array_push($this->context, $context);
17 }
18 public function popContext() {
19 array_pop($this->context);
20 }
21
22 public function fatal($message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL, $v6=NULL) {
23 $what=$this->write('[FATAL]', $message, $v1, $v2, $v3, $v4, $v5, $v6);
24 die($what);
25 }
26 public function debug($message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL, $v6=NULL) {
27 $this->write('[DEBUG]', $message, $v1, $v2, $v3, $v4, $v5, $v6);
28 }
29 public function info($message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL, $v6=NULL) {
30 $this->write('[INFO] ', $message, $v1, $v2, $v3, $v4, $v5, $v6);
31 }
32 public function error($message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL, $v6=NULL) {
33 $this->write('[ERROR]', $message, $v1, $v2, $v3, $v4, $v5, $v6);
34 }
35 private function dump($v) {
36 if(is_array($v) && count($v)==0) {
37 $v='[]';
38 }
39 if($v!=NULL) {
40 if(is_array($v) || is_object($v)) {
41 $v=print_r($v, TRUE);
42 }
43 }
44 if(is_bool($v)) {
45 $v=($v ? 'TRUE' : 'FALSE');
46 }
47 return $v;
48 }
49 private function write($verbosity, $message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL, $v6=NULL) {
50 global $tcmp;
51
52 $text=sprintf($message
53 , $this->dump($v1)
54 , $this->dump($v2)
55 , $this->dump($v3)
56 , $this->dump($v4)
57 , $this->dump($v5)
58 , $this->dump($v6));
59 $message=date("d/m/Y H:i:s")." ".$verbosity." ";
60 if(count($this->context)>0) {
61 $message.='{'.$this->context[count($this->context)-1].'} ';
62 }
63 $message="\n".$message.$text;
64 if(!$tcmp->Options->isLoggerEnable()) {
65 return $message;
66 }
67
68 $hasErrors=false;
69 $filename=TCMP_PLUGIN_DIR."logs/".$this->name."_".date("Ym").".txt";
70 if (!$handle = fopen($filename, 'a')) {
71 $hasErrors=true;
72 }
73
74 if(!$hasErrors && fwrite($handle, $message)===FALSE) {
75 $hasErrors=true;
76 }
77
78 if(!$hasErrors) {
79 fclose($handle);
80 }
81 return $message;
82 }
83 }