Skip to content

Instantly share code, notes, and snippets.

@lrdgz
Created August 2, 2018 15:07
Show Gist options
  • Save lrdgz/03e3132c0585e1f3b8e93a326d1d8970 to your computer and use it in GitHub Desktop.
Save lrdgz/03e3132c0585e1f3b8e93a326d1d8970 to your computer and use it in GitHub Desktop.
<?php
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;
}
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