RESAZIP-PC\resaz

update daitoquerylog

...@@ -91,18 +91,56 @@ extension=bcmath ...@@ -91,18 +91,56 @@ extension=bcmath
91 # 3) Restart web server / PHP-FPM service 91 # 3) Restart web server / PHP-FPM service
92 ``` 92 ```
93 93
94 +## DaitoString
95 +
96 +### convertToUtf8 (Japanese text file -> UTF-8)
97 +
98 +`DaitoString::convertToUtf8()` converts Japanese-encoded text files to UTF-8.
99 +
100 +- Prefer `nkf` when available
101 +- Fallback to `mb_convert_encoding` when `nkf` is unavailable
102 +
103 +Install `nkf` (Ubuntu/Debian):
104 +
105 +```bash
106 +sudo apt install nkf
107 +```
108 +
109 +Example:
110 +
111 +```php
112 +DaitoString::convertToUtf8('/tmp/source.csv');
113 +DaitoString::convertToUtf8('/tmp/source.csv', '/tmp/out', 'source_utf8.csv', 1);
114 +```
115 +
94 ## QueryLog (Laravel shared package) 116 ## QueryLog (Laravel shared package)
95 117
118 +> **Provider registration note**
119 +>
120 +> This package supports Laravel package auto-discovery via `composer.json`:
121 +> `Daito\Lib\DaitoQueryLog\Providers\DaitoQueryLogProvider`.
122 +>
123 +> In normal cases, child projects do **not** need to register the provider manually.
124 +> If a child project uses `"dont-discover"` for this package, add it manually in
125 +> `config/app.php`:
126 +>
127 +> ```php
128 +> 'providers' => [
129 +> // ...
130 +> Daito\Lib\DaitoQueryLog\Providers\DaitoQueryLogProvider::class,
131 +> ],
132 +> ```
133 +
96 ### 1) Publish config in child project 134 ### 1) Publish config in child project
97 ```bash 135 ```bash
98 -php artisan vendor:publish --tag=query-log-config 136 +php artisan vendor:publish --tag=daito-query-log-config
99 ``` 137 ```
100 138
101 -This creates `config/query_log.php` so each project can tune its own settings. 139 +This creates `config/daito-query-log.php` so each project can tune its own settings.
102 140
103 ### 2) Publish migration in child project 141 ### 2) Publish migration in child project
104 ```bash 142 ```bash
105 -php artisan vendor:publish --tag=query-log-migrations 143 +php artisan vendor:publish --tag=daito-query-log-migrations
106 php artisan migrate 144 php artisan migrate
107 ``` 145 ```
108 146
...@@ -116,7 +154,7 @@ This publishes a production-oriented migration for `log_queries` with key indexe ...@@ -116,7 +154,7 @@ This publishes a production-oriented migration for `log_queries` with key indexe
116 154
117 ### 3) Minimal table fields 155 ### 3) Minimal table fields
118 156
119 -Use your own migration and ensure these columns exist in the configured table (`query_log.table`): 157 +Use your own migration and ensure these columns exist in the configured table (`daito-query-log.table`):
120 158
121 - `action` (string) 159 - `action` (string)
122 - `query` (longText/text) 160 - `query` (longText/text)
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
20 "extra": { 20 "extra": {
21 "laravel": { 21 "laravel": {
22 "providers": [ 22 "providers": [
23 - "Daito\\Lib\\QueryLog\\Providers\\QueryLogProvider" 23 + "Daito\\Lib\\DaitoQueryLog\\Providers\\DaitoQueryLogProvider"
24 ] 24 ]
25 } 25 }
26 } 26 }
......
1 <?php 1 <?php
2 2
3 -namespace Daito\Lib\QueryLog\Jobs; 3 +namespace Daito\Lib\DaitoQueryLog\Jobs;
4 4
5 -use Illuminate\Contracts\Queue\ShouldQueue;
6 use Illuminate\Bus\Queueable; 5 use Illuminate\Bus\Queueable;
6 +use Illuminate\Contracts\Queue\ShouldQueue;
7 use Illuminate\Foundation\Bus\Dispatchable; 7 use Illuminate\Foundation\Bus\Dispatchable;
8 use Illuminate\Queue\InteractsWithQueue; 8 use Illuminate\Queue\InteractsWithQueue;
9 use Illuminate\Queue\SerializesModels; 9 use Illuminate\Queue\SerializesModels;
10 use Illuminate\Support\Facades\DB; 10 use Illuminate\Support\Facades\DB;
11 11
12 -class SaveQueryLogJob implements ShouldQueue 12 +class DaitoSaveQueryLogJob implements ShouldQueue
13 { 13 {
14 use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; 14 use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
15 15
...@@ -26,8 +26,8 @@ class SaveQueryLogJob implements ShouldQueue ...@@ -26,8 +26,8 @@ class SaveQueryLogJob implements ShouldQueue
26 return; 26 return;
27 } 27 }
28 28
29 - DB::connection(config('query_log.connection', 'query_log')) 29 + DB::connection(config('daito-query-log.connection', 'query_log'))
30 - ->table(config('query_log.table', 'log_queries')) 30 + ->table(config('daito-query-log.table', 'log_queries'))
31 ->insert($this->arrQueries); 31 ->insert($this->arrQueries);
32 } 32 }
33 } 33 }
......
1 <?php 1 <?php
2 2
3 -namespace Daito\Lib\QueryLog\Models; 3 +namespace Daito\Lib\DaitoQueryLog\Models;
4 4
5 use Illuminate\Database\Eloquent\Model; 5 use Illuminate\Database\Eloquent\Model;
6 6
7 -class QueryLog extends Model 7 +class DaitoQueryLog extends Model
8 { 8 {
9 /** 9 /**
10 * The table associated with the model. 10 * The table associated with the model.
...@@ -39,7 +39,7 @@ class QueryLog extends Model ...@@ -39,7 +39,7 @@ class QueryLog extends Model
39 * 39 *
40 * @var array<int, string> 40 * @var array<int, string>
41 */ 41 */
42 - protected $fillable = [ 42 + protected $fillable = array(
43 'action', 43 'action',
44 'query', 44 'query',
45 'query_type', 45 'query_type',
...@@ -50,14 +50,14 @@ class QueryLog extends Model ...@@ -50,14 +50,14 @@ class QueryLog extends Model
50 'ip', 50 'ip',
51 'user_id', 51 'user_id',
52 'is_screen', 52 'is_screen',
53 - ]; 53 + );
54 protected $connection = 'query_log'; 54 protected $connection = 'query_log';
55 55
56 public function __construct(array $arrAttributes = array()) 56 public function __construct(array $arrAttributes = array())
57 { 57 {
58 parent::__construct($arrAttributes); 58 parent::__construct($arrAttributes);
59 59
60 - $this->setConnection(config('query_log.connection', 'query_log')); 60 + $this->setConnection(config('daito-query-log.connection', 'query_log'));
61 - $this->setTable(config('query_log.table', 'log_queries')); 61 + $this->setTable(config('daito-query-log.table', 'log_queries'));
62 } 62 }
63 } 63 }
......
1 <?php 1 <?php
2 2
3 -namespace Daito\Lib\QueryLog\Providers; 3 +namespace Daito\Lib\DaitoQueryLog\Providers;
4 4
5 use Carbon\Carbon; 5 use Carbon\Carbon;
6 -use Daito\Lib\QueryLog\Jobs\SaveQueryLogJob; 6 +use Daito\Lib\DaitoQueryLog\Jobs\DaitoSaveQueryLogJob;
7 use Illuminate\Database\Connection; 7 use Illuminate\Database\Connection;
8 use Illuminate\Database\Events\QueryExecuted; 8 use Illuminate\Database\Events\QueryExecuted;
9 use Illuminate\Database\Events\TransactionCommitted; 9 use Illuminate\Database\Events\TransactionCommitted;
...@@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Event; ...@@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Event;
14 use Illuminate\Support\ServiceProvider; 14 use Illuminate\Support\ServiceProvider;
15 use Throwable; 15 use Throwable;
16 16
17 -class QueryLogProvider extends ServiceProvider 17 +class DaitoQueryLogProvider extends ServiceProvider
18 { 18 {
19 private $arrQueriesByConnection = array(); 19 private $arrQueriesByConnection = array();
20 private $arrLoggedCountsByConnection = array(); 20 private $arrLoggedCountsByConnection = array();
...@@ -22,8 +22,8 @@ class QueryLogProvider extends ServiceProvider ...@@ -22,8 +22,8 @@ class QueryLogProvider extends ServiceProvider
22 public function register(): void 22 public function register(): void
23 { 23 {
24 $this->mergeConfigFrom( 24 $this->mergeConfigFrom(
25 - __DIR__ . '/../config/query_log.php', 25 + __DIR__ . '/../config/daito-query-log.php',
26 - 'query_log' 26 + 'daito-query-log'
27 ); 27 );
28 } 28 }
29 29
...@@ -47,7 +47,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -47,7 +47,7 @@ class QueryLogProvider extends ServiceProvider
47 return; 47 return;
48 } 48 }
49 49
50 - if ((float) $query->time < (float) config('query_log.min_time', 0)) { 50 + if ((float) $query->time < (float) config('daito-query-log.min_time', 0)) {
51 return; 51 return;
52 } 52 }
53 53
...@@ -124,18 +124,18 @@ class QueryLogProvider extends ServiceProvider ...@@ -124,18 +124,18 @@ class QueryLogProvider extends ServiceProvider
124 return; 124 return;
125 } 125 }
126 126
127 - $chunkSize = max(1, (int) config('query_log.chunk', 200)); 127 + $chunkSize = max(1, (int) config('daito-query-log.chunk', 200));
128 if (!$force && count($arrBuffer) < $chunkSize) { 128 if (!$force && count($arrBuffer) < $chunkSize) {
129 return; 129 return;
130 } 130 }
131 131
132 foreach (array_chunk($arrBuffer, $chunkSize) as $arrQueries) { 132 foreach (array_chunk($arrBuffer, $chunkSize) as $arrQueries) {
133 - $job = new SaveQueryLogJob($arrQueries); 133 + $job = new DaitoSaveQueryLogJob($arrQueries);
134 - if (config('query_log.queue_connection') !== null) { 134 + if (config('daito-query-log.queue_connection') !== null) {
135 - $job->onConnection(config('query_log.queue_connection')); 135 + $job->onConnection(config('daito-query-log.queue_connection'));
136 } 136 }
137 - if (config('query_log.queue_name') !== null) { 137 + if (config('daito-query-log.queue_name') !== null) {
138 - $job->onQueue(config('query_log.queue_name')); 138 + $job->onQueue(config('daito-query-log.queue_name'));
139 } 139 }
140 140
141 dispatch($job); 141 dispatch($job);
...@@ -158,7 +158,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -158,7 +158,7 @@ class QueryLogProvider extends ServiceProvider
158 158
159 private function canLogMoreQueries($connectionName): bool 159 private function canLogMoreQueries($connectionName): bool
160 { 160 {
161 - $maxQueries = max(1, (int) config('query_log.max_queries_per_request', 1000)); 161 + $maxQueries = max(1, (int) config('daito-query-log.max_queries_per_request', 1000));
162 $currentCount = $this->arrLoggedCountsByConnection[$connectionName] ?? 0; 162 $currentCount = $this->arrLoggedCountsByConnection[$connectionName] ?? 0;
163 163
164 return $currentCount < $maxQueries; 164 return $currentCount < $maxQueries;
...@@ -166,7 +166,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -166,7 +166,7 @@ class QueryLogProvider extends ServiceProvider
166 166
167 private function isIgnoredTableSql($sql): bool 167 private function isIgnoredTableSql($sql): bool
168 { 168 {
169 - $arrIgnoreTables = (array) config('query_log.ignore_tables', array()); 169 + $arrIgnoreTables = (array) config('daito-query-log.ignore_tables', array());
170 if ($arrIgnoreTables === array()) { 170 if ($arrIgnoreTables === array()) {
171 return false; 171 return false;
172 } 172 }
...@@ -214,7 +214,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -214,7 +214,7 @@ class QueryLogProvider extends ServiceProvider
214 private function buildPayload(QueryExecuted $query, $queryVerb, $connectionName): array 214 private function buildPayload(QueryExecuted $query, $queryVerb, $connectionName): array
215 { 215 {
216 $rawSql = $this->interpolateSql($query->sql, $query->bindings); 216 $rawSql = $this->interpolateSql($query->sql, $query->bindings);
217 - $maxSqlLength = max(256, (int) config('query_log.max_sql_length', 4000)); 217 + $maxSqlLength = max(256, (int) config('daito-query-log.max_sql_length', 4000));
218 $sql = mb_substr($rawSql, 0, $maxSqlLength); 218 $sql = mb_substr($rawSql, 0, $maxSqlLength);
219 219
220 return array( 220 return array(
...@@ -245,8 +245,8 @@ class QueryLogProvider extends ServiceProvider ...@@ -245,8 +245,8 @@ class QueryLogProvider extends ServiceProvider
245 245
246 private function quoteBinding($binding, $isSensitive = false): string 246 private function quoteBinding($binding, $isSensitive = false): string
247 { 247 {
248 - if ($isSensitive && (bool) config('query_log.mask_sensitive_bindings', true)) { 248 + if ($isSensitive && (bool) config('daito-query-log.mask_sensitive_bindings', true)) {
249 - return "'" . (string) config('query_log.masked_value', '***') . "'"; 249 + return "'" . (string) config('daito-query-log.masked_value', '***') . "'";
250 } 250 }
251 251
252 if ($binding === null) { 252 if ($binding === null) {
...@@ -267,7 +267,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -267,7 +267,7 @@ class QueryLogProvider extends ServiceProvider
267 267
268 private function isSensitiveBinding($interpolatedSql, int $bindingIndex): bool 268 private function isSensitiveBinding($interpolatedSql, int $bindingIndex): bool
269 { 269 {
270 - $arrSensitiveKeywords = (array) config('query_log.sensitive_keywords', array()); 270 + $arrSensitiveKeywords = (array) config('daito-query-log.sensitive_keywords', array());
271 if ($arrSensitiveKeywords === array()) { 271 if ($arrSensitiveKeywords === array()) {
272 return false; 272 return false;
273 } 273 }
...@@ -315,7 +315,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -315,7 +315,7 @@ class QueryLogProvider extends ServiceProvider
315 { 315 {
316 if (app()->runningInConsole()) { 316 if (app()->runningInConsole()) {
317 $command = $this->resolveConsoleCommand(); 317 $command = $this->resolveConsoleCommand();
318 - return $this->matchPatterns($command, (array) config('query_log.skip_command_patterns', array())); 318 + return $this->matchPatterns($command, (array) config('daito-query-log.skip_command_patterns', array()));
319 } 319 }
320 320
321 $request = request(); 321 $request = request();
...@@ -330,7 +330,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -330,7 +330,7 @@ class QueryLogProvider extends ServiceProvider
330 330
331 $arrTargets = array($routeName, $routePath, $fullUrl); 331 $arrTargets = array($routeName, $routePath, $fullUrl);
332 foreach ($arrTargets as $target) { 332 foreach ($arrTargets as $target) {
333 - if ($this->matchPatterns($target, (array) config('query_log.skip_route_patterns', array()))) { 333 + if ($this->matchPatterns($target, (array) config('daito-query-log.skip_route_patterns', array()))) {
334 return true; 334 return true;
335 } 335 }
336 } 336 }
...@@ -372,7 +372,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -372,7 +372,7 @@ class QueryLogProvider extends ServiceProvider
372 372
373 private function isPassedSampling(): bool 373 private function isPassedSampling(): bool
374 { 374 {
375 - $sampleRate = (float) config('query_log.sample_rate', 100); 375 + $sampleRate = (float) config('daito-query-log.sample_rate', 100);
376 if ($sampleRate >= 100) { 376 if ($sampleRate >= 100) {
377 return true; 377 return true;
378 } 378 }
...@@ -392,7 +392,7 @@ class QueryLogProvider extends ServiceProvider ...@@ -392,7 +392,7 @@ class QueryLogProvider extends ServiceProvider
392 private function shouldLogInCurrentRuntime(): bool 392 private function shouldLogInCurrentRuntime(): bool
393 { 393 {
394 if (app()->runningInConsole()) { 394 if (app()->runningInConsole()) {
395 - return (bool) config('query_log.log_on_console', false); 395 + return (bool) config('daito-query-log.log_on_console', false);
396 } 396 }
397 397
398 return true; 398 return true;
...@@ -400,24 +400,24 @@ class QueryLogProvider extends ServiceProvider ...@@ -400,24 +400,24 @@ class QueryLogProvider extends ServiceProvider
400 400
401 private function isEnabled(): bool 401 private function isEnabled(): bool
402 { 402 {
403 - return (bool) config('query_log.enable', false); 403 + return (bool) config('daito-query-log.enable', false);
404 } 404 }
405 405
406 private function registerPublishableResources(): void 406 private function registerPublishableResources(): void
407 { 407 {
408 $this->publishes( 408 $this->publishes(
409 array( 409 array(
410 - __DIR__ . '/../config/query_log.php' => config_path('query_log.php'), 410 + __DIR__ . '/../config/daito-query-log.php' => config_path('daito-query-log.php'),
411 ), 411 ),
412 - 'query-log-config' 412 + 'daito-query-log-config'
413 ); 413 );
414 414
415 $this->publishes( 415 $this->publishes(
416 array( 416 array(
417 - __DIR__ . '/../database/migrations/2026_02_20_000000_create_log_queries_table.php' 417 + __DIR__ . '/../database/migrations/2026_02_20_000000_daito_create_log_queries_table.php'
418 - => database_path('migrations/' . date('Y_m_d_His') . '_create_log_queries_table.php'), 418 + => database_path('migrations/' . date('Y_m_d_His') . '_daito_create_log_queries_table.php'),
419 ), 419 ),
420 - 'query-log-migrations' 420 + 'daito-query-log-migrations'
421 ); 421 );
422 } 422 }
423 } 423 }
......
1 <?php 1 <?php
2 -return [ 2 +
3 +return array(
3 'enable' => env('ENABLE_QUERY_LOG', false), 4 'enable' => env('ENABLE_QUERY_LOG', false),
4 'log_on_console' => env('QUERY_LOG_ON_CONSOLE', false), 5 'log_on_console' => env('QUERY_LOG_ON_CONSOLE', false),
5 'sample_rate' => env('QUERY_LOG_SAMPLE_RATE', 100), // 0-100 (%) 6 'sample_rate' => env('QUERY_LOG_SAMPLE_RATE', 100), // 0-100 (%)
...@@ -45,4 +46,4 @@ return [ ...@@ -45,4 +46,4 @@ return [
45 'migrations', 46 'migrations',
46 'mst_batch', 47 'mst_batch',
47 ), 48 ),
48 -]; 49 +);
......
...@@ -7,8 +7,8 @@ use Illuminate\Support\Facades\Schema; ...@@ -7,8 +7,8 @@ use Illuminate\Support\Facades\Schema;
7 return new class extends Migration { 7 return new class extends Migration {
8 public function up(): void 8 public function up(): void
9 { 9 {
10 - $connection = config('query_log.connection', 'query_log'); 10 + $connection = config('daito-query-log.connection', 'query_log');
11 - $table = config('query_log.table', 'log_queries'); 11 + $table = config('daito-query-log.table', 'log_queries');
12 12
13 Schema::connection($connection)->create($table, function (Blueprint $table) { 13 Schema::connection($connection)->create($table, function (Blueprint $table) {
14 $table->bigIncrements('id'); 14 $table->bigIncrements('id');
...@@ -34,8 +34,8 @@ return new class extends Migration { ...@@ -34,8 +34,8 @@ return new class extends Migration {
34 34
35 public function down(): void 35 public function down(): void
36 { 36 {
37 - $connection = config('query_log.connection', 'query_log'); 37 + $connection = config('daito-query-log.connection', 'query_log');
38 - $table = config('query_log.table', 'log_queries'); 38 + $table = config('daito-query-log.table', 'log_queries');
39 39
40 Schema::connection($connection)->dropIfExists($table); 40 Schema::connection($connection)->dropIfExists($table);
41 } 41 }
......
...@@ -97,7 +97,8 @@ class DaitoString ...@@ -97,7 +97,8 @@ class DaitoString
97 /** 97 /**
98 * Convert Japanese-encoded text file to UTF-8. 98 * Convert Japanese-encoded text file to UTF-8.
99 * Prefer nkf when available, fallback to mb_convert_encoding. 99 * Prefer nkf when available, fallback to mb_convert_encoding.
100 - * 100 + * To install nkf, you can use the following command:
101 + * sudo apt install nkf
101 * Example: 102 * Example:
102 * DaitoString::convertToUtf8('/tmp/source.csv'); 103 * DaitoString::convertToUtf8('/tmp/source.csv');
103 * DaitoString::convertToUtf8('/tmp/source.csv', '/tmp/out', 'source_utf8.csv', 1); 104 * DaitoString::convertToUtf8('/tmp/source.csv', '/tmp/out', 'source_utf8.csv', 1);
......