Skip to content

Instantly share code, notes, and snippets.

@imroca
Created February 5, 2022 19:42
Show Gist options
  • Save imroca/797062c2219dc31fed5df3ba1866fa43 to your computer and use it in GitHub Desktop.
Save imroca/797062c2219dc31fed5df3ba1866fa43 to your computer and use it in GitHub Desktop.
PHP Simple Logging function
// Simple log
function logme($data, $group = 'default')
{
$type = strtolower(gettype($data));
$message = '';
if (in_array($type, ['object', 'array', 'resource', 'resource (closed)'])) {
$message = print_r($data, true);
} elseif (in_array($type, ['boolean', 'null', 'unknown type'])) {
$message = var_export($data, true);
} else {
$message = $data;
}
error_log("[" . date("Y-m-d H:i:s", time()) . "][" . $group . "] (" . $type . ") " . $message . "\n" . basename(__FILE__) . ":" . __LINE__ . " \n", 3, dirname(__FILE__) . "/" . date("Ymd", time()) . ".log");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment