diff --git a/backend/app/api/v1/container.go b/backend/app/api/v1/container.go index 12b31972d..5e6be161f 100644 --- a/backend/app/api/v1/container.go +++ b/backend/app/api/v1/container.go @@ -307,6 +307,15 @@ func (b *BaseApi) Inspect(c *gin.Context) { helper.SuccessWithData(c, result) } +// @Tags Container +// @Summary Container logs +// @Description 容器日志 +// @Param container query string false "容器名称" +// @Param since query string false "时间筛选" +// @Param follow query string false "是否追踪" +// @Param tail query string false "显示行号" +// @Security ApiKeyAuth +// @Router /containers/search/log [post] func (b *BaseApi) ContainerLogs(c *gin.Context) { wsConn, err := upGrader.Upgrade(c.Writer, c.Request, nil) if err != nil { diff --git a/backend/app/service/container.go b/backend/app/service/container.go index e0516561f..f3df901c2 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -1,7 +1,6 @@ package service import ( - "bufio" "context" "encoding/json" "fmt" @@ -354,9 +353,9 @@ func (u *ContainerService) ContainerLogs(wsConn *websocket.Conn, container, sinc return err } - reader := bufio.NewReader(stdout) + buffer := make([]byte, 1024) for { - bytes, err := reader.ReadBytes('\n') + n, err := stdout.Read(buffer) if err != nil { if err == io.EOF { break @@ -364,7 +363,7 @@ func (u *ContainerService) ContainerLogs(wsConn *websocket.Conn, container, sinc global.LOG.Errorf("read bytes from container log failed, err: %v", err) continue } - if err = wsConn.WriteMessage(websocket.TextMessage, bytes); err != nil { + if err = wsConn.WriteMessage(websocket.TextMessage, buffer[:n]); err != nil { global.LOG.Errorf("send message with container log to ws failed, err: %v", err) break } diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 4670f0d06..47dcd1dcb 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -490,8 +490,8 @@ var doc = `{ "installId", "operate" ], - "formatEN": "[appKey] App [appName] [operate]", - "formatZH": "[appKey] 应用 [appName] [operate]", + "formatEN": "[operate] App [appKey][appName]", + "formatZH": "[operate] 应用 [appKey][appName]", "paramKeys": [] } } @@ -2327,32 +2327,37 @@ var doc = `{ } ], "description": "容器日志", - "consumes": [ - "application/json" - ], "tags": [ "Container" ], "summary": "Container logs", "parameters": [ { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.ContainerLog" - } + "type": "string", + "description": "容器名称", + "name": "container", + "in": "query" + }, + { + "type": "string", + "description": "时间筛选", + "name": "since", + "in": "query" + }, + { + "type": "string", + "description": "是否追踪", + "name": "follow", + "in": "query" + }, + { + "type": "string", + "description": "显示行号", + "name": "tail", + "in": "query" } ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - } - } + "responses": {} } }, "/containers/stats/:id": { @@ -10635,21 +10640,6 @@ var doc = `{ } } }, - "dto.ContainerLog": { - "type": "object", - "required": [ - "containerID", - "mode" - ], - "properties": { - "containerID": { - "type": "string" - }, - "mode": { - "type": "string" - } - } - }, "dto.ContainerOperation": { "type": "object", "required": [ @@ -10825,8 +10815,8 @@ var doc = `{ }, "week": { "type": "integer", - "maximum": 7, - "minimum": 1 + "maximum": 6, + "minimum": 0 } } }, @@ -10904,8 +10894,8 @@ var doc = `{ }, "week": { "type": "integer", - "maximum": 7, - "minimum": 1 + "maximum": 6, + "minimum": 0 } } }, @@ -12347,10 +12337,10 @@ var doc = `{ "dto.SSHHistory": { "type": "object", "properties": { - "Area": { + "address": { "type": "string" }, - "address": { + "area": { "type": "string" }, "authMode": { diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index e7671c0b3..63807b809 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -476,8 +476,8 @@ "installId", "operate" ], - "formatEN": "[appKey] App [appName] [operate]", - "formatZH": "[appKey] 应用 [appName] [operate]", + "formatEN": "[operate] App [appKey][appName]", + "formatZH": "[operate] 应用 [appKey][appName]", "paramKeys": [] } } @@ -2313,32 +2313,37 @@ } ], "description": "容器日志", - "consumes": [ - "application/json" - ], "tags": [ "Container" ], "summary": "Container logs", "parameters": [ { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/dto.ContainerLog" - } + "type": "string", + "description": "容器名称", + "name": "container", + "in": "query" + }, + { + "type": "string", + "description": "时间筛选", + "name": "since", + "in": "query" + }, + { + "type": "string", + "description": "是否追踪", + "name": "follow", + "in": "query" + }, + { + "type": "string", + "description": "显示行号", + "name": "tail", + "in": "query" } ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - } - } + "responses": {} } }, "/containers/stats/:id": { @@ -10621,21 +10626,6 @@ } } }, - "dto.ContainerLog": { - "type": "object", - "required": [ - "containerID", - "mode" - ], - "properties": { - "containerID": { - "type": "string" - }, - "mode": { - "type": "string" - } - } - }, "dto.ContainerOperation": { "type": "object", "required": [ @@ -10811,8 +10801,8 @@ }, "week": { "type": "integer", - "maximum": 7, - "minimum": 1 + "maximum": 6, + "minimum": 0 } } }, @@ -10890,8 +10880,8 @@ }, "week": { "type": "integer", - "maximum": 7, - "minimum": 1 + "maximum": 6, + "minimum": 0 } } }, @@ -12333,10 +12323,10 @@ "dto.SSHHistory": { "type": "object", "properties": { - "Area": { + "address": { "type": "string" }, - "address": { + "area": { "type": "string" }, "authMode": { diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 81be0fce5..872bb21aa 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -290,16 +290,6 @@ definitions: $ref: '#/definitions/dto.VolumeHelper' type: array type: object - dto.ContainerLog: - properties: - containerID: - type: string - mode: - type: string - required: - - containerID - - mode - type: object dto.ContainerOperation: properties: name: @@ -415,8 +405,8 @@ definitions: website: type: string week: - maximum: 7 - minimum: 1 + maximum: 6 + minimum: 0 type: integer required: - name @@ -469,8 +459,8 @@ definitions: website: type: string week: - maximum: 7 - minimum: 1 + maximum: 6 + minimum: 0 type: integer required: - id @@ -1437,10 +1427,10 @@ definitions: type: object dto.SSHHistory: properties: - Area: - type: string address: type: string + area: + type: string authMode: type: string date: @@ -3670,8 +3660,8 @@ paths: bodyKeys: - installId - operate - formatEN: '[appKey] App [appName] [operate]' - formatZH: '[appKey] 应用 [appName] [operate]' + formatEN: '[operate] App [appKey][appName]' + formatZH: '[operate] 应用 [appKey][appName]' paramKeys: [] /apps/installed/params/:appInstallId: get: @@ -4836,21 +4826,25 @@ paths: - Container /containers/search/log: post: - consumes: - - application/json description: 容器日志 parameters: - - description: request - in: body - name: request - required: true - schema: - $ref: '#/definitions/dto.ContainerLog' - responses: - "200": - description: OK - schema: - type: string + - description: 容器名称 + in: query + name: container + type: string + - description: 时间筛选 + in: query + name: since + type: string + - description: 是否追踪 + in: query + name: follow + type: string + - description: 显示行号 + in: query + name: tail + type: string + responses: {} security: - ApiKeyAuth: [] summary: Container logs diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index ba5e38170..a14f98ae1 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -61,10 +61,6 @@ export namespace Container { networkTX: number; shotTime: Date; } - export interface ContainerLogSearch { - containerID: string; - mode: string; - } export interface ContainerInspect { id: string; type: string; diff --git a/frontend/src/api/modules/container.ts b/frontend/src/api/modules/container.ts index 1384c20ac..e1f8c79d9 100644 --- a/frontend/src/api/modules/container.ts +++ b/frontend/src/api/modules/container.ts @@ -8,9 +8,6 @@ export const searchContainer = (params: Container.ContainerSearch) => { export const createContainer = (params: Container.ContainerCreate) => { return http.post(`/containers`, params, 3000000); }; -export const logContainer = (params: Container.ContainerLogSearch) => { - return http.post(`/containers/search/log`, params, 400000); -}; export const cleanContainerLog = (containerName: string) => { return http.post(`/containers/clean/log`, { name: containerName }); }; diff --git a/frontend/src/components/container-log/index.vue b/frontend/src/components/container-log/index.vue index bd53c1d02..eef300cfa 100644 --- a/frontend/src/components/container-log/index.vue +++ b/frontend/src/components/container-log/index.vue @@ -2,8 +2,19 @@
+ + + +
{{ $t('commons.button.watch') }}
@@ -34,14 +45,14 @@