MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / setLog

Function setLog

agent/utils/docker/docker.go:170–194  ·  view source on GitHub ↗
(id, newLastLine string, task *task.Task)

Source from the content-addressed store, hash-verified

168}
169
170func setLog(id, newLastLine string, task *task.Task) error {
171 data, err := os.ReadFile(task.Task.LogFile)
172 if err != nil {
173 return fmt.Errorf("failed to read file: %v", err)
174 }
175 lines := strings.Split(string(data), "\n")
176 exist := false
177 for index, line := range lines {
178 if strings.Contains(line, id) {
179 timeStr := time.Now().Format("2006/01/02 15:04:05")
180 lines[index] = timeStr + " " + newLastLine
181 exist = true
182 break
183 } else {
184 lines[index] = strings.TrimSpace(lines[index])
185 }
186 }
187 if !exist {
188 task.Log(newLastLine)
189 return nil
190 }
191 output := strings.Join(lines, "\n")
192 _ = os.WriteFile(task.Task.LogFile, []byte(output), os.ModePerm)
193 return nil
194}
195
196func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string, options image.PullOptions) error {
197 out, err := c.cli.ImagePull(context.Background(), imageName, options)

Callers 4

handlePullImageProcessFunction · 0.85
logProcessFunction · 0.85

Calls 3

WriteFileMethod · 0.80
FormatMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected