mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
remove unused code
This commit is contained in:
parent
01432fa778
commit
7129e2cc9d
2 changed files with 9 additions and 41 deletions
|
@ -31,10 +31,6 @@ func init() {
|
||||||
}
|
}
|
||||||
prefixLength := len(timeFmt) + 5 // level takes 3 + 2 spaces
|
prefixLength := len(timeFmt) + 5 // level takes 3 + 2 spaces
|
||||||
prefix = strings.Repeat(" ", prefixLength)
|
prefix = strings.Repeat(" ", prefixLength)
|
||||||
|
|
||||||
if zerolog.TraceLevel != -1 && zerolog.NoLevel != 6 {
|
|
||||||
panic("zerolog implementation changed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fmtMessage(msg string) string {
|
func fmtMessage(msg string) string {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -11,11 +12,9 @@ import (
|
||||||
|
|
||||||
"github.com/coder/websocket"
|
"github.com/coder/websocket"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
"github.com/yusing/go-proxy/internal/logging"
|
||||||
"github.com/yusing/go-proxy/internal/net/gphttp"
|
"github.com/yusing/go-proxy/internal/net/gphttp"
|
||||||
"github.com/yusing/go-proxy/internal/net/gphttp/gpwebsocket"
|
"github.com/yusing/go-proxy/internal/net/gphttp/gpwebsocket"
|
||||||
"github.com/yusing/go-proxy/internal/task"
|
|
||||||
F "github.com/yusing/go-proxy/internal/utils/functional"
|
F "github.com/yusing/go-proxy/internal/utils/functional"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,8 +28,6 @@ type memLogger struct {
|
||||||
notifyLock sync.RWMutex
|
notifyLock sync.RWMutex
|
||||||
connChans F.Map[chan *logEntryRange, struct{}]
|
connChans F.Map[chan *logEntryRange, struct{}]
|
||||||
listeners F.Map[chan []byte, struct{}]
|
listeners F.Map[chan []byte, struct{}]
|
||||||
|
|
||||||
bufPool sync.Pool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemLogger io.Writer
|
type MemLogger io.Writer
|
||||||
|
@ -43,44 +40,20 @@ const (
|
||||||
maxMemLogSize = 16 * 1024
|
maxMemLogSize = 16 * 1024
|
||||||
truncateSize = maxMemLogSize / 2
|
truncateSize = maxMemLogSize / 2
|
||||||
initialWriteChunkSize = 4 * 1024
|
initialWriteChunkSize = 4 * 1024
|
||||||
bufPoolSize = 256
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var memLoggerInstance = &memLogger{
|
var memLoggerInstance = &memLogger{
|
||||||
connChans: F.NewMapOf[chan *logEntryRange, struct{}](),
|
connChans: F.NewMapOf[chan *logEntryRange, struct{}](),
|
||||||
listeners: F.NewMapOf[chan []byte, struct{}](),
|
listeners: F.NewMapOf[chan []byte, struct{}](),
|
||||||
bufPool: sync.Pool{
|
|
||||||
New: func() any {
|
|
||||||
return &buffer{
|
|
||||||
data: make([]byte, 0, bufPoolSize),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
memLoggerInstance.Grow(maxMemLogSize)
|
memLoggerInstance.Grow(maxMemLogSize)
|
||||||
|
w := zerolog.MultiLevelWriter(os.Stderr, memLoggerInstance)
|
||||||
if common.DebugMemLogger {
|
logging.InitLogger(w)
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
log.SetOutput(w)
|
||||||
|
log.SetPrefix("")
|
||||||
go func() {
|
log.SetFlags(0)
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-task.RootContextCanceled():
|
|
||||||
return
|
|
||||||
case <-ticker.C:
|
|
||||||
logging.Info().Msgf("mem logger size: %d, active conns: %d",
|
|
||||||
memLoggerInstance.Len(),
|
|
||||||
memLoggerInstance.connChans.Size())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
logging.InitLogger(zerolog.MultiLevelWriter(os.Stderr, memLoggerInstance))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMemLogger() MemLogger {
|
func GetMemLogger() MemLogger {
|
||||||
|
@ -133,8 +106,7 @@ func (m *memLogger) notifyWS(pos, n int) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if m.listeners.Size() > 0 {
|
if m.listeners.Size() > 0 {
|
||||||
msg := make([]byte, n)
|
msg := m.Buffer.Bytes()[pos : pos+n]
|
||||||
copy(msg, m.Buffer.Bytes()[pos:pos+n])
|
|
||||||
m.listeners.Range(func(ch chan []byte, _ struct{}) bool {
|
m.listeners.Range(func(ch chan []byte, _ struct{}) bool {
|
||||||
select {
|
select {
|
||||||
case <-timeout.C:
|
case <-timeout.C:
|
||||||
|
@ -199,8 +171,8 @@ func (m *memLogger) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
m.wsStreamLog(r.Context(), conn, logCh)
|
m.wsStreamLog(r.Context(), conn, logCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memLogger) events() (<-chan []byte, func()) {
|
func (m *memLogger) events() (logs <-chan []byte, cancel func()) {
|
||||||
ch := make(chan []byte, 10)
|
ch := make(chan []byte)
|
||||||
m.notifyLock.Lock()
|
m.notifyLock.Lock()
|
||||||
defer m.notifyLock.Unlock()
|
defer m.notifyLock.Unlock()
|
||||||
m.listeners.Store(ch, struct{}{})
|
m.listeners.Store(ch, struct{}{})
|
||||||
|
|
Loading…
Add table
Reference in a new issue