Last active
January 29, 2016 05:20
-
-
Save lloydzhou/6a4e5f549905c4fa5e59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function logger($path = 'php.log', $cond = true) { | |
$logs = array(); | |
register_shutdown_function(function() use ($path, &$logs){ | |
return count($logs) > 0 ? @file_put_contents($path, implode(array_map(function($log){ | |
return count($log) > 1 ? call_user_func_array('sprintf', $log) : current($log); | |
}, $logs), PHP_EOL). PHP_EOL, FILE_APPEND | LOCK_EX) : false; | |
}); | |
$cond = is_callable($cond) ? call_user_func($cond) : !!($cond); | |
return function () use ($cond, &$logs) { | |
return $cond && func_num_args() > 0 ? $logs[] = func_get_args() : false; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment