Skip to content

Instantly share code, notes, and snippets.

@sachinrana95
Created December 15, 2017 14:16
Show Gist options
  • Select an option

  • Save sachinrana95/1308763c326b098ce6ac1108ec546d2b to your computer and use it in GitHub Desktop.

Select an option

Save sachinrana95/1308763c326b098ce6ac1108ec546d2b to your computer and use it in GitHub Desktop.
Generate logs for api
<?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