mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
Without --log-file the viewer said "log printed to console, please see log in console", which the Windows service, the launchd job and every "log to console" setup cannot do. The logger now also keeps its last 4 MiB in memory and the viewer reads that tail when there is no file; the lines carry the same timestamp and level prefix as the file adapter's. The log area also gave way to nothing: at 50vh a short window pushed the filters and the export button below the fold with only a scrollbar to hint at them. It now shrinks so the footer stays visible.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"bufio"
|
|
"github.com/v2rayA/v2rayA/pkg/util/log"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/v2rayA/v2rayA/common"
|
|
"github.com/v2rayA/v2rayA/conf"
|
|
)
|
|
|
|
type getLogQuery struct {
|
|
Skip int64 `json:"skip" form:"skip"`
|
|
}
|
|
|
|
func GetLogger(ctx *gin.Context) {
|
|
config := conf.GetEnvironmentConfig()
|
|
query := getLogQuery{}
|
|
if ctx.ShouldBindQuery(&query) != nil {
|
|
common.ResponseError(ctx, badRequest("skip", "skip must be an integer"))
|
|
return
|
|
}
|
|
if config.LogFile == "" {
|
|
// No file to read: serve the in-memory tail. When the caller's
|
|
// offset is older than what is still held, the data starts at the
|
|
// oldest line kept; the viewer only appends, so the gap is invisible.
|
|
data, _ := log.ReadMemory(query.Skip)
|
|
ctx.String(200, string(data))
|
|
return
|
|
}
|
|
f, err := os.Open(config.LogFile)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
defer f.Close()
|
|
_, err = f.Seek(query.Skip, io.SeekStart)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
data, err := io.ReadAll(bufio.NewReader(f))
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
ctx.String(200, string(data))
|
|
}
|