Permalink
Browse files

Start

  • Loading branch information...
1 parent a74818b commit 98e1a8cb6670e89293aedd49792f0355b0d32596 Brian Fenton committed Oct 7, 2010
Showing with 44 additions and 44 deletions.
  1. +44 −44 src/KLogger.php
View
@@ -1,61 +1,61 @@
<?php
- /**
- * Finally, a light, permissions-checking logging class.
- *
- * Author : Kenny Katzgrau <katzgrau@gmail.com>
- * Date : July 26, 2008
- * Comments : Originally written for use with wpSearch
- * Website : http://codefury.net
- * Version : 1.0
- *
- * Usage:
- * $log = new KLogger ( "log.txt" , KLogger::INFO );
- * $log->_logInfo("Returned a million search results"); //Prints to the log file
- * $log->_logFatal("Oh dear."); //Prints to the log file
- * $log->_logDebug("x = 5"); //Prints nothing due to priority setting
- */
-
- /**
- * Class documentation
- */
+/**
+* Finally, a light, permissions-checking logging class.
+*
+* Author : Kenny Katzgrau <katzgrau@gmail.com>
+* Date : July 26, 2008
+* Comments : Originally written for use with wpSearch
+* Website : http://codefury.net
+* Version : 1.0
+*
+* Usage:
+* $log = new KLogger ( "log.txt" , KLogger::INFO );
+* $log->_logInfo("Returned a million search results"); //Prints to the log file
+* $log->_logFatal("Oh dear."); //Prints to the log file
+* $log->_logDebug("x = 5"); //Prints nothing due to priority setting
+*/
+
+/**
+* Class documentation
+*/
class KLogger
{
- const DEBUG = 1; // Most Verbose
- const INFO = 2; // ...
- const WARN = 3; // ...
- const ERROR = 4; // ...
- const FATAL = 5; // Least Verbose
- const OFF = 6; // Nothing at all.
+ const DEBUG = 1; // Most Verbose
+ const INFO = 2; // ...
+ const WARN = 3; // ...
+ const ERROR = 4; // ...
+ const FATAL = 5; // Least Verbose
+ const OFF = 6; // Nothing at all.
- const LOG_OPEN = 1;
+ const LOG_OPEN = 1;
const OPEN_FAILED = 2;
- const LOG_CLOSED = 3;
+ const LOG_CLOSED = 3;
/* Public members: Not so much of an example of encapsulation, but that's okay. */
- private $_logStatus = self::LOG_CLOSED;
- private static $_defaultPriority = self::DEBUG;
- private static $_dateFormat = "Y-m-d G:i:s";
+ private $_logStatus = self::LOG_CLOSED;
+ private static $_defaultPriority = self::DEBUG;
+ private static $_dateFormat = "Y-m-d G:i:s";
private static $_defaultPermissions= 0777;
- private $_messageQueue = array();
- private $_logFile = NULL;
- private $_priority = self::INFO;
- private $_fileHandle = NULL;
+ private $_messageQueue = array();
+ private $_logFile = NULL;
+ private $_priority = self::INFO;
+ private $_fileHandle = NULL;
private static $instances = array();
public static function instance($logDirectory = FALSE, $priority = FALSE)
{
if($priority === FALSE) $priority = self::$_defaultPriority;
-
+
if($logDirectory === FALSE)
{
if(count(self::$instances) > 0)
return self::$instances[0];
else
$logDirectory = dirname(__FILE__);
}
-
+
if(in_array($logDirectory, self::$instances))
{
return self::$instances[$logDirectory];
@@ -72,12 +72,12 @@ public function __construct($logDirectory, $priority)
if($priority == self::OFF) return;
- $this->_logFile = $logDirectory
+ $this->_logFile = $logDirectory
. DIRECTORY_SEPARATOR
. 'log_'
. date('Y-m-d')
. '.txt';
-
+
$this->_priority = $priority;
if(!file_exists($logDirectory))
{
@@ -88,20 +88,20 @@ public function __construct($logDirectory, $priority)
{
if (!is_writable($this->_logFile))
{
- $this->_logStatus = self::OPEN_FAILED;
+ $this->_logStatus = self::OPEN_FAILED;
$this->_messageQueue[] = "The file exists, but could not be opened for writing. Check that appropriate permissions have been set.";
return;
}
}
if(($this->_fileHandle = fopen($this->_logFile, "a" )))
{
- $this->_logStatus = self::LOG_OPEN;
+ $this->_logStatus = self::LOG_OPEN;
$this->_messageQueue[] = "The log file was opened successfully.";
}
else
{
- $this->_logStatus = self::OPEN_FAILED;
+ $this->_logStatus = self::OPEN_FAILED;
$this->_messageQueue[] = "The file could not be opened. Check permissions.";
}
}
@@ -165,17 +165,17 @@ private function _getTimeLine($level)
switch($level)
{
case self::INFO:
- return "$time - INFO -->";
+ return "$time - INFO -->";
case self::WARN:
- return "$time - WARN -->";
+ return "$time - WARN -->";
case self::DEBUG:
return "$time - DEBUG -->";
case self::ERROR:
return "$time - ERROR -->";
case self::FATAL:
return "$time - FATAL -->";
default:
- return "$time - LOG -->";
+ return "$time - LOG -->";
}
}

0 comments on commit 98e1a8c

Please sign in to comment.