Skip to content

Commit b9a348a

Browse files
Merge pull request #21 from ginkelsoft-development/feature/add-debug-logging
add optional debug logging for search index operations
2 parents 4f264fa + 515d6ba commit b9a348a

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
@@ -126,6 +126,16 @@ public function updateSearchIndex(): void
126126
return;
127127
}
128128

129+
// Debug logging
130+
if (config('encrypted-search.debug', false)) {
131+
logger()->debug('[EncryptedSearch] Updating search index', [
132+
'model' => static::class,
133+
'model_id' => $this->getKey(),
134+
'token_count' => count($rows),
135+
'backend' => $useElastic ? 'elasticsearch' : 'database',
136+
]);
137+
}
138+
129139
// Choose backend: Elasticsearch or Database
130140
if ($useElastic) {
131141
$this->syncToElasticsearch($rows);
@@ -152,6 +162,15 @@ public function removeSearchIndex(): void
152162
{
153163
$useElastic = config('encrypted-search.elasticsearch.enabled', false);
154164

165+
// Debug logging
166+
if (config('encrypted-search.debug', false)) {
167+
logger()->debug('[EncryptedSearch] Removing search index', [
168+
'model' => static::class,
169+
'model_id' => $this->getKey(),
170+
'backend' => $useElastic ? 'elasticsearch' : 'database',
171+
]);
172+
}
173+
155174
if ($useElastic) {
156175
$this->removeFromElasticsearch();
157176
} else {

0 commit comments

Comments
 (0)