Created
December 15, 2017 14:16
-
-
Save sachinrana95/1308763c326b098ce6ac1108ec546d2b to your computer and use it in GitHub Desktop.
Generate logs for api
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 | |
| /** | |
| * Method for generate log for api,, Get request and response. | |
| * Need to create 'logs.log' blank file where you want to generate log. | |
| *@param array, pass the array. | |
| */ | |
| function _log($data, $logType = "INFO") { | |
| $file = __DIR__."/logs.log"; | |
| if (count($data) && file_exists($file) && is_writable($file)) { | |
| $data = (is_array($data) || is_object($data)) ? json_encode($data) : $data; | |
| $dayTime = date('D h:i'); | |
| $content = "[" . $logType . "] [" . $dayTime . "]" . PHP_EOL . PHP_EOL . $data . PHP_EOL . PHP_EOL; | |
| file_put_contents($file, $content, FILE_APPEND); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment