Skip to content

Commit 792e871

Browse files
committed
perf: cache nginx prefix for log file scanning
1 parent fa0d785 commit 792e871

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/nginx_log/nginx_log.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import (
1515
)
1616

1717
// Regular expression for log directives - matches access_log or error_log
18-
var logDirectiveRegex = regexp.MustCompile(`(?m)(access_log|error_log)\s+([^\s;]+)(?:\s+[^;]+)?;`)
18+
var (
19+
logDirectiveRegex = regexp.MustCompile(`(?m)(access_log|error_log)\s+([^\s;]+)(?:\s+[^;]+)?;`)
20+
prefix = ""
21+
)
1922

2023
// Use init function to automatically register callback
2124
func init() {
25+
prefix = nginx.GetPrefix()
2226
// Register the callback directly with the global registry
2327
cache.RegisterCallback(scanForLogDirectives)
2428
}
@@ -32,7 +36,6 @@ func scanForLogDirectives(configPath string, content []byte) error {
3236
// Find log directives using regex
3337
matches := logDirectiveRegex.FindAllSubmatch(content, -1)
3438

35-
prefix := nginx.GetPrefix()
3639
// Parse log paths
3740
for _, match := range matches {
3841
if len(match) >= 3 {

0 commit comments

Comments
 (0)