Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ APP_URL=http://EC2-Manager.test

LOG_CHANNEL=stack
LOG_LEVEL=debug
LOG_DATABASE=true

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
Expand Down
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ APP_URL=http://EC2-Manager.test

LOG_CHANNEL=stack
LOG_LEVEL=debug
LOG_DATABASE=true

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
Expand Down
18 changes: 17 additions & 1 deletion app/Orchid/Screens/MachineSharedUrlEditScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ public function commandBar(): array
->canSee($this->exists),
];
}

/**
*
* Function to generate random strings
*
*/

function generateRandomString($length = 50) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}

/**
* Views.
Expand Down Expand Up @@ -110,7 +126,7 @@ public function layout(): array
->title('Text'),

Input::make('machinesharedurl.url')
->title('URL'),
->title('URL')->value($this->generateRandomString()),

Relation::make('machinesharedurl.idMachine')
->title('Id machine')
Expand Down
35 changes: 35 additions & 0 deletions app/Providers/Debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Services\Database\Logger as LoggerDatabase;

class Debug extends ServiceProvider
{
/**
* @return void
*/
public function boot()
{
$this->logging();
}

/**
* @return void
*/
protected function logging(): void
{
$this->loggingDatabase();
}

/**
* @return void
*/
protected function loggingDatabase(): void
{
if (config('logging.channels.database.enabled')) {
LoggerDatabase::listen();
}
}
}
75 changes: 75 additions & 0 deletions app/Services/Database/Logger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php declare(strict_types=1);

namespace App\Services\Database;

use DateTime;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Request;

class Logger
{
/**
* @var string
*/
protected static string $file = '';

/**
* @return void
*/
public static function listen(): void
{
if (static::$file) {
return;
}

static::load();
static::write('['.date('Y-m-d H:i:s').'] ['.Request::method().'] '.Request::fullUrl());

DB::listen(static function ($sql) {
foreach ($sql->bindings as $i => $binding) {
if ($binding instanceof DateTime) {
$sql->bindings[$i] = $binding->format('Y-m-d H:i:s');
} elseif (is_string($binding)) {
$sql->bindings[$i] = "'${binding}'";
} elseif (is_bool($binding)) {
$sql->bindings[$i] = $binding ? 'true' : 'false';
}
}

static::write(vsprintf(str_replace(['%', '?'], ['%%', '%s'], $sql->sql), $sql->bindings));
});
}

/**
* @return void
*/
protected static function load(): void
{
static::file();

if (is_dir($dir = dirname(static::$file)) === false) {
mkdir($dir, 0755, true);
}
}

/**
* @return void
*/
protected static function file(): void
{
$file = array_filter(explode('-', preg_replace('/[^a-z0-9]+/i', '-', Request::path())));
$file = implode('-', array_map(static fn ($value) => substr($value, 0, 20), $file)) ?: '-';

static::$file = storage_path('logs/query/'.date('Y-m-d').'/'.substr($file, 0, 150).'.log');
}

/**
* @param string $message
*
* @return void
*/
protected static function write(string $message): void
{
file_put_contents(static::$file, "\n\n".$message, FILE_APPEND | LOCK_EX);
}
}
Loading