MCPcopy
hub / github.com/keploy/keploy / Swap

Method Swap

utils/log/logger.go:512–524  ·  view source on GitHub ↗

Swap atomically swaps the underlying file the sink writes to. The caller opens newFile; the previous file is returned so the caller can close it after Swap returns. Buffered writes are flushed to the previous file before the swap, and the cap-tripped state is reset. Concurrent log Writes are safe —

(newFile *os.File)

Source from the content-addressed store, hash-verified

510// cappedWriteSyncer's mutex, so no record can land half-written
511// across the swap boundary.
512func (s *DebugFileSink) Swap(newFile *os.File) error {
513 if s == nil || s.capped == nil || s.buffered == nil || newFile == nil {
514 return fmt.Errorf("debug file sink: swap called on uninitialized sink or nil file")
515 }
516 s.mu.Lock()
517 defer s.mu.Unlock()
518 if err := s.buffered.Sync(); err != nil {
519 return fmt.Errorf("debug file sink: flush before swap: %w", err)
520 }
521 s.capped.swap(zapcore.AddSync(newFile))
522 s.originPath = newFile.Name()
523 return nil
524}
525
526// RotateForScope swaps the sink to a per-scope file derived from the
527// sink's origin path. Scope semantics are caller-defined; for the

Callers 8

CloseMethod · 0.80
BeginTestErrorCaptureMethod · 0.80
EndTestErrorCaptureMethod · 0.80
GetMockErrorsMethod · 0.80
MarkMockIncompleteMethod · 0.80
CloseMethod · 0.80
CloseMethod · 0.80

Calls 3

swapMethod · 0.80
NameMethod · 0.80
SyncMethod · 0.45

Tested by

no test coverage detected