Skip to content

Instantly share code, notes, and snippets.

@atomicpages
Created October 15, 2014 20:31
Show Gist options
  • Save atomicpages/315c5154bd3a8ffdd151 to your computer and use it in GitHub Desktop.
Save atomicpages/315c5154bd3a8ffdd151 to your computer and use it in GitHub Desktop.
A really simple logging class
<?php
/**
* Class Log
* A really simple logging class that writes flat data to a file.
* @author Dennis Thompson
* @license MIT
* @version 1.0
* @copyright AtomicPages LLC 2014
*/
class Log {
private $handle, $dateFormat;
public function __construct($file, $mode = "a") {
$this->handle = fopen($file, $mode);
$this->dateFormat = "d/M/Y H:i:s";
}
public function dateFormat($format) {
$this->dateFormat = $format;
}
public function getDateFormat() {
return $this->dateFormat;
}
/**
* Writes info to the log
* @param mixed, string or an array to write to log
* @access public
*/
public function log($entries) {
if(is_string($entries)) {
fwrite($this->handle, "Error: [" . date($this->dateFormat) . "] " . $entries . "\n");
} else {
foreach($entries as $value) {
fwrite($this->handle, "Error: [" . date($this->dateFormat) . "] " . $value . "\n");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment