feat: logs lines support '-' sign means starting log file lines (#365)

This commit is contained in:
naison
2024-10-30 09:10:20 +08:00
committed by GitHub
parent f966cd29d7
commit 6e052a5a0b
2 changed files with 6 additions and 2 deletions

View File

@@ -58,6 +58,6 @@ func CmdLogs(f cmdutil.Factory) *cobra.Command {
},
}
cmd.Flags().BoolVarP(&req.Follow, "follow", "f", false, "Specify if the logs should be streamed.")
cmd.Flags().Int32VarP(&req.Lines, "number", "N", 10, "The location is number lines.")
cmd.Flags().Int32VarP(&req.Lines, "number", "N", 10, "Lines of recent log file to display.")
return cmd
}

View File

@@ -20,7 +20,11 @@ func (svr *Server) Logs(req *rpc.LogRequest, resp rpc.Daemon_LogsServer) error {
}
// only show latest N lines
lines -= req.Lines
if req.Lines < 0 {
lines = -req.Lines
} else {
lines -= req.Lines
}
config := tail.Config{Follow: req.Follow, ReOpen: false, MustExist: true, Logger: log.New(io.Discard, "", log.LstdFlags)}
if !req.Follow {