Skip to content

Commit 1d76e54

Browse files
authored
fix:Asynchronous log writing has not taken effect (#10000)
Make it effective by modifying the queue
1 parent 22c903f commit 1d76e54

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

core/log/writer.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package log
22

33
import (
4+
"github.com/1Panel-dev/1Panel/core/constant"
45
"log"
56
"os"
67
"path"
@@ -9,9 +10,6 @@ import (
910
"sync"
1011
"sync/atomic"
1112
"time"
12-
"unsafe"
13-
14-
"github.com/1Panel-dev/1Panel/core/constant"
1513

1614
"github.com/1Panel-dev/1Panel/core/global"
1715
)
@@ -23,12 +21,12 @@ type Writer struct {
2321
fire chan string
2422
cf *Config
2523
rollingfilech chan string
24+
queue chan []byte
2625
}
2726

2827
type AsynchronousWriter struct {
2928
Writer
3029
ctx chan int
31-
queue chan []byte
3230
errChan chan error
3331
closed int32
3432
wg sync.WaitGroup
@@ -100,6 +98,7 @@ func NewWriterFromConfig(c *Config) (RollingWriter, error) {
10098

10199
var rollingWriter RollingWriter
102100
writer := Writer{
101+
queue: make(chan []byte, BufferSize),
103102
m: mng,
104103
file: file,
105104
absPath: filepath,
@@ -156,17 +155,15 @@ func NewWriterFromConfig(c *Config) (RollingWriter, error) {
156155

157156
wr := &AsynchronousWriter{
158157
ctx: make(chan int),
159-
queue: make(chan []byte, QueueSize),
160158
errChan: make(chan error, QueueSize),
161159
wg: sync.WaitGroup{},
162160
closed: 0,
163161
Writer: writer,
164162
}
165-
163+
rollingWriter = wr
166164
wr.wg.Add(1)
167165
go wr.writer()
168166
wr.wg.Wait()
169-
rollingWriter = wr
170167

171168
return rollingWriter, nil
172169
}
@@ -211,9 +208,10 @@ func (w *Writer) Write(b []byte) (int, error) {
211208
}
212209
}
213210

214-
fp := atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&w.file)))
215-
file := (*os.File)(fp)
216-
return file.Write(b)
211+
select {
212+
case w.queue <- b:
213+
return len(b), nil
214+
}
217215
}
218216

219217
func (w *Writer) Reopen(file string) error {

0 commit comments

Comments
 (0)