Skip to content

Instantly share code, notes, and snippets.

@cuonghuynh
Last active November 22, 2016 03:20
Show Gist options
  • Save cuonghuynh/6a4a4eadc4f39c7231aed4f6dcf3b419 to your computer and use it in GitHub Desktop.
Save cuonghuynh/6a4a4eadc4f39c7231aed4f6dcf3b419 to your computer and use it in GitHub Desktop.
Write logs into seperate files in laravel 5.x
class LogUtil
{
/**
* Write a content out file log
* @param string $file
* @param string $content
* @return boolean
*/
public static function write($file, $content)
{
$logDir = config('feedsreader.log.path');
$path = sprintf('%s/%s.log', $logDir, $file);
$serialized = sprintf('%s: %s' . "\n", Carbon::now(), $content);
if (\File::exists($path)) {
return \File::append($path, $serialized);
}
return \File::put($path, $content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment