Skip to content

Commit f90c677

Browse files
add optional debug logging for search index operations
This commit introduces a configurable debug logging feature that helps developers and operators monitor encrypted search index operations. Changes: - Added 'debug' configuration option in encrypted-search.php - Implemented conditional logging in updateSearchIndex() method - Implemented conditional logging in removeSearchIndex() method - Logs include model class, model ID, token count, and backend type The logging only activates when ENCRYPTED_SEARCH_DEBUG=true is set in the environment configuration, preventing unnecessary log noise in production environments.
1 parent 6975c73 commit f90c677

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

config/encrypted-search.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,18 @@
8282
'host' => env('ELASTICSEARCH_HOST', 'http://elasticsearch:9200'),
8383
'index' => env('ELASTICSEARCH_INDEX', 'encrypted_search'),
8484
],
85+
86+
/*
87+
|--------------------------------------------------------------------------
88+
| Debug Logging
89+
|--------------------------------------------------------------------------
90+
|
91+
| Enable debug logging for encrypted search operations. When enabled,
92+
| the package will log token generation, index updates, and deletions
93+
| to help with debugging and monitoring.
94+
|
95+
| Warning: This can generate a lot of log entries in high-traffic applications.
96+
|
97+
*/
98+
'debug' => env('ENCRYPTED_SEARCH_DEBUG', false),
8599
];

src/Traits/HasEncryptedSearchIndex.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ public function updateSearchIndex(): void
121121
return;
122122
}
123123

124+
// Debug logging
125+
if (config('encrypted-search.debug', false)) {
126+
logger()->debug('[EncryptedSearch] Updating search index', [
127+
'model' => static::class,
128+
'model_id' => $this->getKey(),
129+
'token_count' => count($rows),
130+
'backend' => $useElastic ? 'elasticsearch' : 'database',
131+
]);
132+
}
133+
124134
// Choose backend: Elasticsearch or Database
125135
if ($useElastic) {
126136
$this->syncToElasticsearch($rows);
@@ -145,6 +155,15 @@ public function removeSearchIndex(): void
145155
{
146156
$useElastic = config('encrypted-search.elasticsearch.enabled', false);
147157

158+
// Debug logging
159+
if (config('encrypted-search.debug', false)) {
160+
logger()->debug('[EncryptedSearch] Removing search index', [
161+
'model' => static::class,
162+
'model_id' => $this->getKey(),
163+
'backend' => $useElastic ? 'elasticsearch' : 'database',
164+
]);
165+
}
166+
148167
if ($useElastic) {
149168
$this->removeFromElasticsearch();
150169
} else {

0 commit comments

Comments
 (0)