]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6009 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Jun 2023 13:41:06 +0000 (15:41 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Jun 2023 13:41:06 +0000 (15:41 +0200)
.env.dev
app/Logging/SlackFormatter.php [new file with mode: 0644]
composer.json
config/logging.php
resources/views/vendor/backpack/base/dashboard.blade.php

index 088dccccbefa4c707ebb87365443765a5b40ae39..10b54ac7636d6e4a8bba55528cc1a90bdb539fa7 100644 (file)
--- a/.env.dev
+++ b/.env.dev
@@ -7,6 +7,7 @@ DEBUGBAR_ENABLED=true
 APP_URL=https://dev.toolbox.fluidbook.com
 HEADER_COLOR="#df4759"
 
+
 LOG_CHANNEL=stack
 APP_LOG=daily
 
diff --git a/app/Logging/SlackFormatter.php b/app/Logging/SlackFormatter.php
new file mode 100644 (file)
index 0000000..e31958c
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace App\Logging;
+
+use App\Models\User;
+use Illuminate\Http\Request;
+use Monolog\Formatter\LineFormatter;
+use Monolog\Handler\SlackWebhookHandler;
+use Monolog\LogRecord;
+
+class SlackFormatter
+{
+    protected $request;
+
+    public function __construct(Request $request = null)
+    {
+        $this->request = $request;
+    }
+
+    public function __invoke($logger)
+    {
+        foreach ($logger->getHandlers() as $handler) {
+            if ($handler instanceof SlackWebhookHandler) {
+                $handler->setFormatter(new LineFormatter(
+                    '[%datetime%] %channel%.%level_name%: %message% %context% %extra%'
+                ));
+
+                $handler->pushProcessor([$this, 'processLogRecord']);
+            }
+        }
+    }
+
+    public function processLogRecord(LogRecord $record): LogRecord
+    {
+
+        if ($this->request) {
+            $record->extra += [
+                'URL' => $this->request->url(),
+            ];
+        }
+        /** @var User $user */
+        $user = backpack_user();
+        if ($user) {
+            $record->extra += [
+                'user' => $user->getNameAttribute() . ' (' . $user->id . ')',
+            ];
+        }
+
+        return $record;
+    }
+}
index 15454517f2790c8655bb0ec80d5d1e999fcffbd6..9dc589110fcad2f459601a6f13f81c3c81838cca 100644 (file)
@@ -51,7 +51,7 @@
         "php-ffmpeg/php-ffmpeg": "^v1.1.0",
         "rodneyrehm/plist": "^2.0",
         "rustici-software/scormcloud-api-v2-client-php": "^2.1.0",
-        "symfony/http-client": "^v6.3.0"
+        "symfony/http-client": "^v6.3.0",
     },
     "require-dev": {
         "spatie/laravel-ignition": "^2.1.3",
index a72b700b9597ef02690fbc6c854f4c7fadd67939..239989aedcbfa99f096e9d2e6ecc20ac4e4019c5 100644 (file)
@@ -56,6 +56,7 @@ return [
 
         'slack' => [
             'driver' => 'slack',
+            'tap' => [\App\Logging\SlackFormatter::class],
             'url' => env('LOG_SLACK_WEBHOOK_URL'),
             'username' => 'Laravel Log',
             'emoji' => ':boom:',
index db8e3d162c94e0fd6b60f570c25f0ebb8305eb6b..29a1198f273e4dfc0ae2b86a3d018ae1fcd98d0f 100644 (file)
@@ -2,6 +2,7 @@
 @extends(backpack_view('blank'))
 
 @php
+    \Illuminate\Support\Facades\Log::warning('test !!');
     \App\Widgets::fluidbookQuoteWidgets();
     \App\Widgets::notificationsWidget(['class' => 'col-sm-8 dashboard-wrapper'],'dashboard',__('Notifications'));
     \App\Widgets::teamWidgets(['class' => 'col-sm-4 dashboard-wrapper'],'dashboard',__('Planning de l\'équipe'));