basic db logging

This commit is contained in:
2024-03-29 15:38:40 +01:00
parent be27833716
commit 51f600f2c0
5 changed files with 156 additions and 3 deletions

View File

@@ -24,8 +24,9 @@ class ProductsCompareController extends Controller
$codes = $request->input("codes");
$countries = $request->input("countries");
$online = $request->input("online");
$text = $request->input("text");
Log::info("{codes} {countries}", ["codes" => $codes, "countries" => $countries, "online" => $online]);
Log::channel('db')->info("{codes} {countries} {online} {text}", ["codes" => $codes, "countries" => $countries, "online" => $online, "text" => $text]);
$codes = collect($codes);
$countries = collect($countries);

View File

@@ -20,7 +20,8 @@
"pusher/pusher-php-server": "^7.0",
"spatie/laravel-permission": "^5.5",
"tightenco/ziggy": "^1.0",
"torann/geoip": "^3.0"
"torann/geoip": "^3.0",
"yoeriboven/laravel-log-db": "^1.2"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.7",

126
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f8f22c83d6734feaadd1beafe3a4b702",
"content-hash": "31ac3d5515d95b8df2c3e650f681dfe2",
"packages": [
{
"name": "bacon/bacon-qr-code",
@@ -5896,6 +5896,66 @@
],
"time": "2023-06-16T10:52:11+00:00"
},
{
"name": "spatie/laravel-package-tools",
"version": "1.16.4",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-package-tools.git",
"reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53",
"reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53",
"shasum": ""
},
"require": {
"illuminate/contracts": "^9.28|^10.0|^11.0",
"php": "^8.0"
},
"require-dev": {
"mockery/mockery": "^1.5",
"orchestra/testbench": "^7.7|^8.0",
"pestphp/pest": "^1.22",
"phpunit/phpunit": "^9.5.24",
"spatie/pest-plugin-test-time": "^1.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\LaravelPackageTools\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"role": "Developer"
}
],
"description": "Tools for creating Laravel packages",
"homepage": "https://github.com/spatie/laravel-package-tools",
"keywords": [
"laravel-package-tools",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-package-tools/issues",
"source": "https://github.com/spatie/laravel-package-tools/tree/1.16.4"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2024-03-20T07:29:11+00:00"
},
{
"name": "spatie/laravel-permission",
"version": "5.11.1",
@@ -8775,6 +8835,70 @@
"source": "https://github.com/webmozarts/assert/tree/1.11.0"
},
"time": "2022-06-03T18:03:27+00:00"
},
{
"name": "yoeriboven/laravel-log-db",
"version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/yoeriboven/laravel-log-db.git",
"reference": "eb4b0c10fafaaa56c3ae8679066926875c45b797"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yoeriboven/laravel-log-db/zipball/eb4b0c10fafaaa56c3ae8679066926875c45b797",
"reference": "eb4b0c10fafaaa56c3ae8679066926875c45b797",
"shasum": ""
},
"require": {
"nesbot/carbon": "^2.72",
"php": "^8.1",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.39",
"nunomaduro/collision": "^6.0",
"orchestra/testbench": "^7.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpunit/phpunit": "^9.5"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Yoeriboven\\LaravelLogDb\\DatabaseLoggerServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Yoeriboven\\LaravelLogDb\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Yoeri Boven",
"email": "yoeriboven@msn.com",
"role": "Developer"
}
],
"description": "A database driver for logging with Laravel",
"homepage": "https://github.com/yoeriboven/laravel-log-db",
"keywords": [
"laravel",
"laravel-log-db",
"yoeriboven"
],
"support": {
"issues": "https://github.com/yoeriboven/laravel-log-db/issues",
"source": "https://github.com/yoeriboven/laravel-log-db/tree/1.2.2"
},
"time": "2024-03-22T00:40:15+00:00"
}
],
"packages-dev": [

View File

@@ -3,6 +3,7 @@
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
use Yoeriboven\LaravelLogDb\DatabaseLogger;
return [
@@ -117,6 +118,11 @@ return [
'emergency' => [
'path' => storage_path('logs/laravel.log'),
],
'db' => [
'driver' => 'custom',
'via' => DatabaseLogger::class,
],
],
];

View File

@@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('log_messages', function (Blueprint $table) {
$table->id();
$table->string('level_name');
$table->unsignedSmallInteger('level');
$table->string('message');
$table->dateTime('logged_at');
$table->json('context');
$table->json('extra');
});
}
};