mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
Fixing too large offsets for default runtime logs (#1587)
This commit is contained in:
parent
52861310b0
commit
da66561d1e
@ -294,11 +294,23 @@ func (r *runtime) Logs(s *Service, options ...LogsOption) (LogStream, error) {
|
||||
return nil, fmt.Errorf("Log file %v does not exists", fpath)
|
||||
}
|
||||
|
||||
// have to check file size to avoid too big of a seek
|
||||
fi, err := os.Stat(fpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
size := fi.Size()
|
||||
|
||||
whence := 2
|
||||
// Multiply by length of an average line of log in bytes
|
||||
offset := -1 * lopts.Count * 200
|
||||
offset := lopts.Count * 200
|
||||
|
||||
t, err := tail.TailFile(logFile(s.Name), tail.Config{Follow: lopts.Stream, Location: &tail.SeekInfo{
|
||||
if offset > size {
|
||||
offset = size
|
||||
}
|
||||
offset *= -1
|
||||
|
||||
t, err := tail.TailFile(fpath, tail.Config{Follow: lopts.Stream, Location: &tail.SeekInfo{
|
||||
Whence: whence,
|
||||
Offset: int64(offset),
|
||||
}, Logger: tail.DiscardingLogger})
|
||||
@ -354,6 +366,7 @@ func (l *logStream) Stop() error {
|
||||
close(l.stream)
|
||||
err := l.tail.Stop()
|
||||
if err != nil {
|
||||
logger.Errorf("Error stopping tail: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user