Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Satini_pvduc
/
daito-utils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
RESAZIP-PC\resaz
2026-02-23 14:27:05 +0700
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
085055ed4a2c0f1a321cc22d90909fad5679d16f
085055ed
1 parent
09ddb5bf
update daitoquerylog
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
91 additions
and
51 deletions
README.md
composer.json
src/QueryLog/Jobs/SaveQueryLogJob.php → src/DaitoQueryLog/Jobs/DaitoSaveQueryLogJob.php
src/QueryLog/Models/QueryLog.php → src/DaitoQueryLog/Models/DaitoQueryLog.php
src/QueryLog/Providers/QueryLogProvider.php → src/DaitoQueryLog/Providers/DaitoQueryLogProvider.php
src/QueryLog/config/query_log.php → src/DaitoQueryLog/config/daito-query-log.php
src/QueryLog/database/migrations/2026_02_20_000000_create_log_queries_table.php → src/DaitoQueryLog/database/migrations/2026_02_20_000000_daito_create_log_queries_table.php
src/DaitoString.php
README.md
View file @
085055e
...
...
@@ -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)
...
...
composer.json
View file @
085055e
...
...
@@ -20,7 +20,7 @@
"extra"
:
{
"laravel"
:
{
"providers"
:
[
"Daito
\\
Lib
\\
QueryLog
\\
Providers
\\
QueryLogProvider"
"Daito
\\
Lib
\\
DaitoQueryLog
\\
Providers
\\
Daito
QueryLogProvider"
]
}
}
...
...
src/
QueryLog/Jobs/
SaveQueryLogJob.php
→
src/
DaitoQueryLog/Jobs/Daito
SaveQueryLogJob.php
View file @
085055e
<?php
namespace
Daito\Lib\QueryLog\Jobs
;
namespace
Daito\Lib\
Daito
QueryLog\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
Daito
SaveQueryLogJob
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
);
}
}
...
...
src/
QueryLog/Models/
QueryLog.php
→
src/
DaitoQueryLog/Models/Daito
QueryLog.php
View file @
085055e
<?php
namespace
Daito\Lib\QueryLog\Models
;
namespace
Daito\Lib\
Daito
QueryLog\Models
;
use
Illuminate\Database\Eloquent\Model
;
class
QueryLog
extends
Model
class
Daito
QueryLog
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'
));
}
}
...
...
src/
QueryLog/Providers/
QueryLogProvider.php
→
src/
DaitoQueryLog/Providers/Daito
QueryLogProvider.php
View file @
085055e
<?php
namespace
Daito\Lib\QueryLog\Providers
;
namespace
Daito\Lib\
Daito
QueryLog\Providers
;
use
Carbon\Carbon
;
use
Daito\Lib\
QueryLog\Jobs\
SaveQueryLogJob
;
use
Daito\Lib\
DaitoQueryLog\Jobs\Daito
SaveQueryLogJob
;
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
Daito
QueryLogProvider
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
Daito
SaveQueryLogJob
(
$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'
);
}
}
...
...
src/
QueryLog/config/query_
log.php
→
src/
DaitoQueryLog/config/daito-query-
log.php
View file @
085055e
<?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'
,
),
]
;
)
;
...
...
src/
QueryLog/database/migrations/2026_02_20_000000
_create_log_queries_table.php
→
src/
DaitoQueryLog/database/migrations/2026_02_20_000000_daito
_create_log_queries_table.php
View file @
085055e
...
...
@@ -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
);
}
...
...
src/DaitoString.php
View file @
085055e
...
...
@@ -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);
...
...
Please
register
or
sign in
to post a comment