feat: read nginx access logs and error logs

This commit is contained in:
0xJacky 2022-08-30 21:22:54 +08:00
parent 6e3004b0bc
commit ea3f1cd25e
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
3 changed files with 44 additions and 11 deletions

View file

@ -14,6 +14,7 @@ import (
type controlStruct struct {
Fetch string `json:"fetch"`
Type string `json:"type"`
}
func tailNginxLog(ws *websocket.Conn, controlChan chan controlStruct, errChan chan error) {
@ -33,10 +34,15 @@ func tailNginxLog(ws *websocket.Conn, controlChan chan controlStruct, errChan ch
seek.Whence = io.SeekEnd
}
logPath := settings.NginxLogSettings.AccessLogPath
if control.Type == "error" {
logPath = settings.NginxLogSettings.ErrorLogPath
}
// Create a tail
t, err := tail.TailFile(
settings.NginxLogSettings.AccessLogPath, tail.Config{Follow: true,
ReOpen: true, Location: &seek})
t, err := tail.TailFile(logPath, tail.Config{Follow: true,
ReOpen: true, Location: &seek})
if err != nil {
errChan <- errors.Wrap(err, "error NginxAccessLog Tail")