php-ldap /log/log.inc.php

Language PHP Lines 101
MD5 Hash 55f3b51f2afd3994f7eead6b890d542c Estimated Cost $1,017 (why?)
Repository https://bitbucket.org/phenobarbital/php-ldap.git View Raw File View Project SPDX
  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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
<?php
class log {
	#instancia unica de la clase
	protected static $instance = null;
	#cache debug lines:
	protected static $_line = 0;
	#buffer de debug:
	protected static $_logbuffer = array();

	#nombre del archivo de log base
	protected static $_writer = null;

	#constructor de la clase
	protected function __construct() {}
	
	public function __destruct() {
		self::show();
	}

	#evitar que sea clonada accidentalmente la clase
	protected function __clone() {}

	/**
	 * GetInstance
	 * crea o accede a una instancia unica del Singleton
	 * @return object::instance
	 * @access public static
	 * @author Jesus Lara
	 */
	public static function getInstance() {
		if(empty(self::$instance)) {
			#crea una nueva instancia de la clase
			self::$instance = new self();
		}
		return self::$instance;
	}
	
	/**
	 * clean_log
	 * Clean and restart logs variables
	 */
	public static function clean() {
		self::$_line = 0;
		self::$_logbuffer = array();
	}

	 

	/**
	 * get_log
	 * retorna el log generado
	 * @return string
	 */
	public static function get() {
		$message = '';
		foreach(self::$_logbuffer as $k=>$v) {
			$msg = "{$k} : {$v}";
			$msg.= "\n";
			$message.= date('c') . '[' . time() . '] ' . $msg;
		}
		return $message;
	}

	/**
	 * show_log
	 * print log information to browser
	 */
	public static function show() {
		echo self::get();
		#para no mostrar 2 veces, se limpia el log al mostrarlo
		self::clean();
	}

	/**
	 * save_log
	 * write log to disk or elsewhere
	 * @access public static
	 * @return none
	 */
	public static function save() {
		return self::$_writer->write(self::get_log());
	}
	
	public static function write() {
		return self::save();
	}

	/**
	 * log
	 * add a log line to logbuffer
	 * @return none
	 * @access public static
	 * @author Jesus Lara
	 */
	public static function log($message) {
		self::$_line++;
		#save to the log buffer:
		self::$_logbuffer[self::$_line] = $message;
	}	
}
?>
Back to Top