<?php namespace App; use Monolog\Logger as MonologLogger; /** * Custom logger to solve the log permissions nightmare */ class Logger { public function __invoke(array $config) { $monolog = new MonologLogger('my-logger'); $filename = storage_path('logs/' . php_sapi_name() . '-' . posix_getpwuid(posix_geteuid())['name'] . '.log'); $monolog->pushHandler($handler = new \Monolog\Handler\RotatingFileHandler($filename, 30)); $handler->setFilenameFormat('laravel-{date}-{filename}', 'Y-m-d'); $formatter = new \Monolog\Formatter\LineFormatter(null, null, true, true); $formatter->includeStacktraces(); $handler->setFormatter($formatter); return $monolog; } }