@@ -3,13 +3,16 @@ package nginx_log
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
7
+ "path/filepath"
6
8
"sync"
7
9
8
10
"github.com/0xJacky/Nginx-UI/internal/nginx_log/analytics"
9
11
"github.com/0xJacky/Nginx-UI/internal/nginx_log/indexer"
10
12
"github.com/0xJacky/Nginx-UI/internal/nginx_log/searcher"
11
13
"github.com/blevesearch/bleve/v2"
12
14
"github.com/uozi-tech/cosy/logger"
15
+ cSettings "github.com/uozi-tech/cosy/settings"
13
16
)
14
17
15
18
// Global instances for new services
@@ -72,6 +75,8 @@ func initializeWithDefaults(ctx context.Context) error {
72
75
73
76
// Initialize parallel indexer with shard manager
74
77
indexerConfig := indexer .DefaultIndexerConfig ()
78
+ // Use config directory for index path
79
+ indexerConfig .IndexPath = getConfigDirIndexPath ()
75
80
shardManager := indexer .NewDefaultShardManager (indexerConfig )
76
81
globalIndexer = indexer .NewParallelIndexer (indexerConfig , shardManager )
77
82
@@ -94,6 +99,28 @@ func initializeWithDefaults(ctx context.Context) error {
94
99
return nil
95
100
}
96
101
102
+ // getConfigDirIndexPath returns the index path relative to the config file directory
103
+ func getConfigDirIndexPath () string {
104
+ // Get the config file path from cosy settings
105
+ if cSettings .ConfPath != "" {
106
+ configDir := filepath .Dir (cSettings .ConfPath )
107
+ indexPath := filepath .Join (configDir , "log-index" )
108
+
109
+ // Ensure the directory exists
110
+ if err := os .MkdirAll (indexPath , 0755 ); err != nil {
111
+ logger .Warnf ("Failed to create index directory at %s: %v, using default" , indexPath , err )
112
+ return "./log-index"
113
+ }
114
+
115
+ logger .Infof ("Using index path: %s" , indexPath )
116
+ return indexPath
117
+ }
118
+
119
+ // Fallback to default relative path
120
+ logger .Warn ("Config file path not available, using default index path" )
121
+ return "./log-index"
122
+ }
123
+
97
124
// GetModernSearcher returns the global searcher instance
98
125
func GetModernSearcher () searcher.Searcher {
99
126
servicesMutex .RLock ()
0 commit comments