diff --git a/agent/app/api/v2/container.go b/agent/app/api/v2/container.go index c79017037..9d8d26e0e 100644 --- a/agent/app/api/v2/container.go +++ b/agent/app/api/v2/container.go @@ -529,7 +529,7 @@ func (b *BaseApi) DownloadContainerLogs(c *gin.Context) { if err := helper.CheckBindAndValidate(&req, c); err != nil { return } - err := containerService.DownloadContainerLogs(req.ContainerType, req.Container, req.Since, strconv.Itoa(int(req.Tail)), c) + err := containerService.DownloadContainerLogs(req.ContainerType, req.Container, req.Since, strconv.Itoa(int(req.Tail)), req.Timestamp, c) if err != nil { helper.InternalServer(c, err) } @@ -757,6 +757,7 @@ func (b *BaseApi) LoadComposeEnv(c *gin.Context) { // @Param since query string false "时间筛选" // @Param follow query string false "是否追踪" // @Param tail query string false "显示行号" +// @Param timestamp query string false "是否显示时间" // @Success 200 // @Security ApiKeyAuth // @Security Timestamp @@ -770,6 +771,7 @@ func (b *BaseApi) ContainerStreamLogs(c *gin.Context) { since := c.Query("since") follow := c.Query("follow") == "true" tail := c.Query("tail") + timestamp := c.Query("timestamp") == "true" container := c.Query("container") compose := c.Query("compose") @@ -779,6 +781,7 @@ func (b *BaseApi) ContainerStreamLogs(c *gin.Context) { Since: since, Follow: follow, Tail: tail, + Timestamp: timestamp, Type: "container", } if compose != "" { diff --git a/agent/app/dto/container.go b/agent/app/dto/container.go index aaa6caf25..5330ef0b9 100644 --- a/agent/app/dto/container.go +++ b/agent/app/dto/container.go @@ -305,6 +305,7 @@ type ContainerLog struct { Container string `json:"container" validate:"required"` Since string `json:"since"` Tail uint `json:"tail"` + Timestamp bool `json:"timestamp"` ContainerType string `json:"containerType"` } @@ -314,5 +315,6 @@ type StreamLog struct { Since string Follow bool Tail string + Timestamp bool Type string } diff --git a/agent/app/service/container.go b/agent/app/service/container.go index 831d7bbc0..b381a02ee 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -80,7 +80,7 @@ type IContainerService interface { ContainerCommit(req dto.ContainerCommit) error ContainerLogClean(req dto.OperationWithName) error ContainerOperation(req dto.ContainerOperation) error - DownloadContainerLogs(containerType, container, since, tail string, c *gin.Context) error + DownloadContainerLogs(containerType, container, since, tail string, timestamp bool, c *gin.Context) error ContainerStats(id string) (*dto.ContainerStats, error) Inspect(req dto.InspectReq) (string, error) @@ -956,6 +956,9 @@ func collectLogs(done <-chan struct{}, params dto.StreamLog, messageChan chan<- if params.Follow { cmdArgs = append(cmdArgs, "-f") } + if params.Timestamp { + cmdArgs = append(cmdArgs, "-t") + } if params.Tail != "0" { cmdArgs = append(cmdArgs, "--tail", params.Tail) } @@ -1052,7 +1055,7 @@ func collectLogs(done <-chan struct{}, params dto.StreamLog, messageChan chan<- _ = dockerCmd.Wait() } -func (u *ContainerService) DownloadContainerLogs(containerType, container, since, tail string, c *gin.Context) error { +func (u *ContainerService) DownloadContainerLogs(containerType, container, since, tail string, timestamp bool, c *gin.Context) error { if cmd.CheckIllegal(container, since, tail) { return buserr.New("ErrCmdIllegal") } @@ -1080,6 +1083,9 @@ func (u *ContainerService) DownloadContainerLogs(containerType, container, since commandArg = append(commandArg, "--since") commandArg = append(commandArg, since) } + if timestamp { + commandArg = append(commandArg, "-t") + } var dockerCmd *exec.Cmd if containerType == "compose" && dockerCommand == "docker-compose" { dockerCmd = exec.Command("docker-compose", commandArg...) diff --git a/core/cmd/server/docs/docs.go b/core/cmd/server/docs/docs.go index 984dfaace..b0ee87206 100644 --- a/core/cmd/server/docs/docs.go +++ b/core/cmd/server/docs/docs.go @@ -4594,6 +4594,12 @@ const docTemplate = `{ "in": "query", "name": "tail", "type": "string" + }, + { + "description": "是否显示时间", + "in": "query", + "name": "timestamp", + "type": "string" } ], "responses": { diff --git a/core/cmd/server/docs/swagger.json b/core/cmd/server/docs/swagger.json index a661603ee..817f1571f 100644 --- a/core/cmd/server/docs/swagger.json +++ b/core/cmd/server/docs/swagger.json @@ -4590,6 +4590,12 @@ "in": "query", "name": "tail", "type": "string" + }, + { + "description": "是否显示时间", + "in": "query", + "name": "timestamp", + "type": "string" } ], "responses": { diff --git a/frontend/src/components/log/container/index.vue b/frontend/src/components/log/container/index.vue index e6995a752..cb7fb659c 100644 --- a/frontend/src/components/log/container/index.vue +++ b/frontend/src/components/log/container/index.vue @@ -17,6 +17,11 @@ {{ $t('commons.button.watch') }} +