diff --git a/.env.example b/.env.example index 3676972563..2fc8fb386f 100644 --- a/.env.example +++ b/.env.example @@ -53,13 +53,6 @@ LOG_CHANNEL=stack # nothing will get logged, ever. APP_LOG_LEVEL=notice -# -# Firefly III keeps track of specific (security) related events in an audit log. -# These are stored on the drive, but in case of Docker can best be sent to 'stdout'. -# -AUDIT_LOG_CHANNEL=daily - - # Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III # For other database types, please see the FAQ: https://docs.firefly-iii.org/support/faq # If you use Docker or similar, you can set these variables from a file by appending them with _FILE diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 3cae751830..dec48c04f4 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -124,6 +124,9 @@ class LoginController extends Controller */ public function showLoginForm(Request $request) { + + Log::channel('audit')->info('Show login form.'); + $count = DB::table('users')->count(); $loginProvider = config('firefly.login_provider'); $title = (string) trans('firefly.login_page_title'); diff --git a/app/Support/Logging/AuditLogger.php b/app/Support/Logging/AuditLogger.php index c624eaea83..43a3fd91f7 100644 --- a/app/Support/Logging/AuditLogger.php +++ b/app/Support/Logging/AuditLogger.php @@ -24,6 +24,11 @@ declare(strict_types=1); namespace FireflyIII\Support\Logging; +use Illuminate\Log\Logger; +use Monolog\Formatter\LineFormatter; +use Monolog\Handler\AbstractProcessingHandler; +use Monolog\Handler\Handler; + /** * Class AuditLogger * @codeCoverageIgnore @@ -33,13 +38,19 @@ class AuditLogger /** * Customize the given logger instance. * - * @param \Illuminate\Log\Logger $logger + * @param Logger $logger * * @return void */ - public function __invoke($logger) + public function __invoke(Logger $logger) { $processor = new AuditProcessor; - $logger->pushProcessor($processor); + /** @var AbstractProcessingHandler $handler */ + foreach ($logger->getHandlers() as $handler) { + $formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"); + $handler->setFormatter($formatter); + $handler->pushProcessor($processor); + } + } } diff --git a/app/Support/Logging/AuditProcessor.php b/app/Support/Logging/AuditProcessor.php index 29a763909d..66d563948b 100644 --- a/app/Support/Logging/AuditProcessor.php +++ b/app/Support/Logging/AuditProcessor.php @@ -38,13 +38,11 @@ class AuditProcessor public function __invoke(array $record): array { $record['extra']['path'] = request()->method() . ':' . request()->url(); - $record['extra']['IP'] = app('request')->ip(); if (auth()->check()) { $record['extra']['user'] = auth()->user()->email; } - return $record; } } diff --git a/config/logging.php b/config/logging.php index 932421f073..509f158197 100644 --- a/config/logging.php +++ b/config/logging.php @@ -56,6 +56,10 @@ return [ 'driver' => 'stack', 'channels' => ['daily', 'stdout'], ], + 'audit' => [ + 'driver' => 'stack', + 'channels' => ['daily_audit', 'stdout'], + ], 'single' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), @@ -77,8 +81,8 @@ return [ 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'), 'days' => 7, ], - 'audit' => [ - 'driver' => envNonEmpty('AUDIT_LOG_CHANNEL', 'daily'), + 'daily_audit' => [ + 'driver' => 'daily', 'path' => storage_path('logs/ff3-audit.log'), 'tap' => [AuditLogger::class], 'level' => 'info',