I wanted to write a simple Log class for PHP, I use ajax calls with AngularJS and often return the log in an array
Example:
$return['data'] = $returnedDataArray;
$return['log'] = $logDataArray;
$return['status'] = 'success';
echo json_encode($return);
I was hoping to implement a logging system in my other classes, like my DB wrapper, etc.
Example:
Log::put('sql', $sql, 'DB');
Log::put('fields', $fieldsArray, 'DB');
And than pass the log.
Example:
$return['log'] = Log::getLog();
Here is my Log class:
class Log {
private static $_loggingOn = true, $_log = array();
public static function put ($key, $value, $className = null, $functionName = null) {
if ($className) {
if ($functionName) {
self::$_log[$className][$functionName][$key] = $value;
} else {
self::$_log[$className][$key] = $value;
}
} else {
self::$_log[$key] = $value;
}
}
public static function getLog () {
if (self::loggingOn()) {
return self::$_log;
}
return array('Logging is turned off.');
}
public static function loggingOn () {
return self::$_loggingOn;
}
}
I am wondering if using the static class would be a recommended approach?
static
, which isn't very useful in a PHP context \$\endgroup\$