Skip to content

Instantly share code, notes, and snippets.

@tai-sho
Last active August 29, 2015 13:58
Show Gist options
  • Save tai-sho/9987673 to your computer and use it in GitHub Desktop.
Save tai-sho/9987673 to your computer and use it in GitHub Desktop.
素のPHPでログを出したいとき
<?php
function debugLog($label, $val) {
static $filename = 'logs/debug.log';
$mtime = microtime();
$timeStmp = explode(' ', $mtime);
$time = date('Y-m-d H:i:s', (int)$timeStmp[1]);
$mtime = number_format($mtime,5);
$val = var_export($val, true);
$val = str_replace('"', '""', $val);
$message = '"'. $time. '","'. $mtime. '","'. $label. '"'."\r\n". $val. '"'. "\r\n";
error_log($message, 3, $filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment