RESAZIP-PC\resaz

update daitoquerylog

......@@ -91,18 +91,56 @@ extension=bcmath
# 3) Restart web server / PHP-FPM service
```
## DaitoString
### convertToUtf8 (Japanese text file -> UTF-8)
`DaitoString::convertToUtf8()` converts Japanese-encoded text files to UTF-8.
- Prefer `nkf` when available
- Fallback to `mb_convert_encoding` when `nkf` is unavailable
Install `nkf` (Ubuntu/Debian):
```bash
sudo apt install nkf
```
Example:
```php
DaitoString::convertToUtf8('/tmp/source.csv');
DaitoString::convertToUtf8('/tmp/source.csv', '/tmp/out', 'source_utf8.csv', 1);
```
## QueryLog (Laravel shared package)
> **Provider registration note**
>
> This package supports Laravel package auto-discovery via `composer.json`:
> `Daito\Lib\DaitoQueryLog\Providers\DaitoQueryLogProvider`.
>
> In normal cases, child projects do **not** need to register the provider manually.
> If a child project uses `"dont-discover"` for this package, add it manually in
> `config/app.php`:
>
> ```php
> 'providers' => [
> // ...
> Daito\Lib\DaitoQueryLog\Providers\DaitoQueryLogProvider::class,
> ],
> ```
### 1) Publish config in child project
```bash
php artisan vendor:publish --tag=query-log-config
php artisan vendor:publish --tag=daito-query-log-config
```
This creates `config/query_log.php` so each project can tune its own settings.
This creates `config/daito-query-log.php` so each project can tune its own settings.
### 2) Publish migration in child project
```bash
php artisan vendor:publish --tag=query-log-migrations
php artisan vendor:publish --tag=daito-query-log-migrations
php artisan migrate
```
......@@ -116,7 +154,7 @@ This publishes a production-oriented migration for `log_queries` with key indexe
### 3) Minimal table fields
Use your own migration and ensure these columns exist in the configured table (`query_log.table`):
Use your own migration and ensure these columns exist in the configured table (`daito-query-log.table`):
- `action` (string)
- `query` (longText/text)
......
......@@ -20,7 +20,7 @@
"extra": {
"laravel": {
"providers": [
"Daito\\Lib\\QueryLog\\Providers\\QueryLogProvider"
"Daito\\Lib\\DaitoQueryLog\\Providers\\DaitoQueryLogProvider"
]
}
}
......
<?php
namespace Daito\Lib\QueryLog\Jobs;
namespace Daito\Lib\DaitoQueryLog\Jobs;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
class SaveQueryLogJob implements ShouldQueue
class DaitoSaveQueryLogJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
......@@ -26,8 +26,8 @@ class SaveQueryLogJob implements ShouldQueue
return;
}
DB::connection(config('query_log.connection', 'query_log'))
->table(config('query_log.table', 'log_queries'))
DB::connection(config('daito-query-log.connection', 'query_log'))
->table(config('daito-query-log.table', 'log_queries'))
->insert($this->arrQueries);
}
}
......
<?php
namespace Daito\Lib\QueryLog\Models;
namespace Daito\Lib\DaitoQueryLog\Models;
use Illuminate\Database\Eloquent\Model;
class QueryLog extends Model
class DaitoQueryLog extends Model
{
/**
* The table associated with the model.
......@@ -39,7 +39,7 @@ class QueryLog extends Model
*
* @var array<int, string>
*/
protected $fillable = [
protected $fillable = array(
'action',
'query',
'query_type',
......@@ -50,14 +50,14 @@ class QueryLog extends Model
'ip',
'user_id',
'is_screen',
];
);
protected $connection = 'query_log';
public function __construct(array $arrAttributes = array())
{
parent::__construct($arrAttributes);
$this->setConnection(config('query_log.connection', 'query_log'));
$this->setTable(config('query_log.table', 'log_queries'));
$this->setConnection(config('daito-query-log.connection', 'query_log'));
$this->setTable(config('daito-query-log.table', 'log_queries'));
}
}
......
<?php
namespace Daito\Lib\QueryLog\Providers;
namespace Daito\Lib\DaitoQueryLog\Providers;
use Carbon\Carbon;
use Daito\Lib\QueryLog\Jobs\SaveQueryLogJob;
use Daito\Lib\DaitoQueryLog\Jobs\DaitoSaveQueryLogJob;
use Illuminate\Database\Connection;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Database\Events\TransactionCommitted;
......@@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Throwable;
class QueryLogProvider extends ServiceProvider
class DaitoQueryLogProvider extends ServiceProvider
{
private $arrQueriesByConnection = array();
private $arrLoggedCountsByConnection = array();
......@@ -22,8 +22,8 @@ class QueryLogProvider extends ServiceProvider
public function register(): void
{
$this->mergeConfigFrom(
__DIR__ . '/../config/query_log.php',
'query_log'
__DIR__ . '/../config/daito-query-log.php',
'daito-query-log'
);
}
......@@ -47,7 +47,7 @@ class QueryLogProvider extends ServiceProvider
return;
}
if ((float) $query->time < (float) config('query_log.min_time', 0)) {
if ((float) $query->time < (float) config('daito-query-log.min_time', 0)) {
return;
}
......@@ -124,18 +124,18 @@ class QueryLogProvider extends ServiceProvider
return;
}
$chunkSize = max(1, (int) config('query_log.chunk', 200));
$chunkSize = max(1, (int) config('daito-query-log.chunk', 200));
if (!$force && count($arrBuffer) < $chunkSize) {
return;
}
foreach (array_chunk($arrBuffer, $chunkSize) as $arrQueries) {
$job = new SaveQueryLogJob($arrQueries);
if (config('query_log.queue_connection') !== null) {
$job->onConnection(config('query_log.queue_connection'));
$job = new DaitoSaveQueryLogJob($arrQueries);
if (config('daito-query-log.queue_connection') !== null) {
$job->onConnection(config('daito-query-log.queue_connection'));
}
if (config('query_log.queue_name') !== null) {
$job->onQueue(config('query_log.queue_name'));
if (config('daito-query-log.queue_name') !== null) {
$job->onQueue(config('daito-query-log.queue_name'));
}
dispatch($job);
......@@ -158,7 +158,7 @@ class QueryLogProvider extends ServiceProvider
private function canLogMoreQueries($connectionName): bool
{
$maxQueries = max(1, (int) config('query_log.max_queries_per_request', 1000));
$maxQueries = max(1, (int) config('daito-query-log.max_queries_per_request', 1000));
$currentCount = $this->arrLoggedCountsByConnection[$connectionName] ?? 0;
return $currentCount < $maxQueries;
......@@ -166,7 +166,7 @@ class QueryLogProvider extends ServiceProvider
private function isIgnoredTableSql($sql): bool
{
$arrIgnoreTables = (array) config('query_log.ignore_tables', array());
$arrIgnoreTables = (array) config('daito-query-log.ignore_tables', array());
if ($arrIgnoreTables === array()) {
return false;
}
......@@ -214,7 +214,7 @@ class QueryLogProvider extends ServiceProvider
private function buildPayload(QueryExecuted $query, $queryVerb, $connectionName): array
{
$rawSql = $this->interpolateSql($query->sql, $query->bindings);
$maxSqlLength = max(256, (int) config('query_log.max_sql_length', 4000));
$maxSqlLength = max(256, (int) config('daito-query-log.max_sql_length', 4000));
$sql = mb_substr($rawSql, 0, $maxSqlLength);
return array(
......@@ -245,8 +245,8 @@ class QueryLogProvider extends ServiceProvider
private function quoteBinding($binding, $isSensitive = false): string
{
if ($isSensitive && (bool) config('query_log.mask_sensitive_bindings', true)) {
return "'" . (string) config('query_log.masked_value', '***') . "'";
if ($isSensitive && (bool) config('daito-query-log.mask_sensitive_bindings', true)) {
return "'" . (string) config('daito-query-log.masked_value', '***') . "'";
}
if ($binding === null) {
......@@ -267,7 +267,7 @@ class QueryLogProvider extends ServiceProvider
private function isSensitiveBinding($interpolatedSql, int $bindingIndex): bool
{
$arrSensitiveKeywords = (array) config('query_log.sensitive_keywords', array());
$arrSensitiveKeywords = (array) config('daito-query-log.sensitive_keywords', array());
if ($arrSensitiveKeywords === array()) {
return false;
}
......@@ -315,7 +315,7 @@ class QueryLogProvider extends ServiceProvider
{
if (app()->runningInConsole()) {
$command = $this->resolveConsoleCommand();
return $this->matchPatterns($command, (array) config('query_log.skip_command_patterns', array()));
return $this->matchPatterns($command, (array) config('daito-query-log.skip_command_patterns', array()));
}
$request = request();
......@@ -330,7 +330,7 @@ class QueryLogProvider extends ServiceProvider
$arrTargets = array($routeName, $routePath, $fullUrl);
foreach ($arrTargets as $target) {
if ($this->matchPatterns($target, (array) config('query_log.skip_route_patterns', array()))) {
if ($this->matchPatterns($target, (array) config('daito-query-log.skip_route_patterns', array()))) {
return true;
}
}
......@@ -372,7 +372,7 @@ class QueryLogProvider extends ServiceProvider
private function isPassedSampling(): bool
{
$sampleRate = (float) config('query_log.sample_rate', 100);
$sampleRate = (float) config('daito-query-log.sample_rate', 100);
if ($sampleRate >= 100) {
return true;
}
......@@ -392,7 +392,7 @@ class QueryLogProvider extends ServiceProvider
private function shouldLogInCurrentRuntime(): bool
{
if (app()->runningInConsole()) {
return (bool) config('query_log.log_on_console', false);
return (bool) config('daito-query-log.log_on_console', false);
}
return true;
......@@ -400,24 +400,24 @@ class QueryLogProvider extends ServiceProvider
private function isEnabled(): bool
{
return (bool) config('query_log.enable', false);
return (bool) config('daito-query-log.enable', false);
}
private function registerPublishableResources(): void
{
$this->publishes(
array(
__DIR__ . '/../config/query_log.php' => config_path('query_log.php'),
__DIR__ . '/../config/daito-query-log.php' => config_path('daito-query-log.php'),
),
'query-log-config'
'daito-query-log-config'
);
$this->publishes(
array(
__DIR__ . '/../database/migrations/2026_02_20_000000_create_log_queries_table.php'
=> database_path('migrations/' . date('Y_m_d_His') . '_create_log_queries_table.php'),
__DIR__ . '/../database/migrations/2026_02_20_000000_daito_create_log_queries_table.php'
=> database_path('migrations/' . date('Y_m_d_His') . '_daito_create_log_queries_table.php'),
),
'query-log-migrations'
'daito-query-log-migrations'
);
}
}
......
<?php
return [
return array(
'enable' => env('ENABLE_QUERY_LOG', false),
'log_on_console' => env('QUERY_LOG_ON_CONSOLE', false),
'sample_rate' => env('QUERY_LOG_SAMPLE_RATE', 100), // 0-100 (%)
......@@ -45,4 +46,4 @@ return [
'migrations',
'mst_batch',
),
];
);
......
......@@ -7,8 +7,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
$connection = config('query_log.connection', 'query_log');
$table = config('query_log.table', 'log_queries');
$connection = config('daito-query-log.connection', 'query_log');
$table = config('daito-query-log.table', 'log_queries');
Schema::connection($connection)->create($table, function (Blueprint $table) {
$table->bigIncrements('id');
......@@ -34,8 +34,8 @@ return new class extends Migration {
public function down(): void
{
$connection = config('query_log.connection', 'query_log');
$table = config('query_log.table', 'log_queries');
$connection = config('daito-query-log.connection', 'query_log');
$table = config('daito-query-log.table', 'log_queries');
Schema::connection($connection)->dropIfExists($table);
}
......
......@@ -97,7 +97,8 @@ class DaitoString
/**
* Convert Japanese-encoded text file to UTF-8.
* Prefer nkf when available, fallback to mb_convert_encoding.
*
* To install nkf, you can use the following command:
* sudo apt install nkf
* Example:
* DaitoString::convertToUtf8('/tmp/source.csv');
* DaitoString::convertToUtf8('/tmp/source.csv', '/tmp/out', 'source_utf8.csv', 1);
......