Skip to content

Commit b496b85

Browse files
committed
fix: Ensure logs are not interrupted, even if the disk becomes full and later recovers.
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
1 parent 2165e30 commit b496b85

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pkg/logging/jsonfile/jsonfile.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ package jsonfile
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"path/filepath"
2425
"strconv"
2526
"strings"
2627
"sync"
28+
"syscall"
2729
"time"
2830

2931
timetypes "github.com/docker/docker/api/types/time"
@@ -43,8 +45,25 @@ func Path(dataStore, ns, id string) string {
4345
return filepath.Join(dataStore, "containers", ns, id, id+"-json.log")
4446
}
4547

48+
type discardWriter struct {
49+
writer io.Writer
50+
}
51+
52+
func (pw *discardWriter) Write(p []byte) (int, error) {
53+
n, err := pw.writer.Write(p)
54+
if err != nil && errors.As(err, new(syscall.Errno)) {
55+
return len(p), nil
56+
}
57+
return n, err
58+
}
59+
60+
func newdiscardWriter(w io.Writer) *discardWriter {
61+
return &discardWriter{writer: w}
62+
}
63+
4664
func Encode(stdout <-chan string, stderr <-chan string, writer io.Writer) error {
47-
enc := json.NewEncoder(writer)
65+
discardWriter := newdiscardWriter(writer)
66+
enc := json.NewEncoder(discardWriter)
4867
var encMu sync.Mutex
4968
var wg sync.WaitGroup
5069
wg.Add(2)

0 commit comments

Comments
 (0)