Created
February 22, 2018 05:30
-
-
Save sachinrana95/cc1695eb5b2742193af204ed72ff7cf9 to your computer and use it in GitHub Desktop.
Generate log in logs file
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