Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions internal/logger/file_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ func InitFileLogger(logDir, fileName string) error {
// withLock acquires fl.mu, executes fn, then releases fl.mu.
// Use this in methods that return an error to avoid repeating the lock/unlock preamble.
func (fl *FileLogger) withLock(fn func() error) error {
fl.mu.Lock()
defer fl.mu.Unlock()
return fn()
return withMutexLock(&fl.mu, fn)
}

// Close closes the log file
Expand Down
9 changes: 9 additions & 0 deletions internal/logger/global_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ package logger

import "sync"

// withMutexLock acquires mu, calls fn, and releases mu.
// It is a package-level helper to avoid repeating the lock/unlock preamble in
// per-type withLock methods.
func withMutexLock(mu *sync.Mutex, fn func() error) error {
mu.Lock()
defer mu.Unlock()
return fn()
}

// closableLogger is a constraint for types that have a Close method.
// This is satisfied by *FileLogger, *JSONLLogger, *MarkdownLogger, *ServerFileLogger, and *ToolsLogger.
type closableLogger interface {
Expand Down
4 changes: 1 addition & 3 deletions internal/logger/jsonl_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ func InitJSONLLogger(logDir, fileName string) error {
// withLock acquires jl.mu, executes fn, then releases jl.mu.
// Use this in methods that return an error to avoid repeating the lock/unlock preamble.
func (jl *JSONLLogger) withLock(fn func() error) error {
jl.mu.Lock()
defer jl.mu.Unlock()
return fn()
return withMutexLock(&jl.mu, fn)
}

// Close closes the JSONL log file
Expand Down
4 changes: 1 addition & 3 deletions internal/logger/markdown_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ func (ml *MarkdownLogger) initializeFile() error {
// withLock acquires ml.mu, executes fn, then releases ml.mu.
// Use this in methods that return an error to avoid repeating the lock/unlock preamble.
func (ml *MarkdownLogger) withLock(fn func() error) error {
ml.mu.Lock()
defer ml.mu.Unlock()
return fn()
return withMutexLock(&ml.mu, fn)
}

// Close closes the log file and writes the closing details tag
Expand Down
4 changes: 1 addition & 3 deletions internal/logger/tools_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ func InitToolsLogger(logDir, fileName string) error {
// withLock acquires tl.mu, executes fn, then releases tl.mu.
// Use this in methods that return an error to avoid repeating the lock/unlock preamble.
func (tl *ToolsLogger) withLock(fn func() error) error {
tl.mu.Lock()
defer tl.mu.Unlock()
return fn()
return withMutexLock(&tl.mu, fn)
}

// LogTools logs the tools for a specific server
Expand Down
Loading