(ctx context.Context, logCtx logContext)
| 205 | } |
| 206 | |
| 207 | func (f *taskFormatter) format(ctx context.Context, logCtx logContext) (string, error) { |
| 208 | if cached, ok := f.cache[logCtx]; ok { |
| 209 | return cached, nil |
| 210 | } |
| 211 | |
| 212 | nodeName, err := f.r.Resolve(ctx, swarm.Node{}, logCtx.nodeID) |
| 213 | if err != nil { |
| 214 | return "", err |
| 215 | } |
| 216 | |
| 217 | serviceName, err := f.r.Resolve(ctx, swarm.Service{}, logCtx.serviceID) |
| 218 | if err != nil { |
| 219 | return "", err |
| 220 | } |
| 221 | |
| 222 | res, err := f.client.TaskInspect(ctx, logCtx.taskID, client.TaskInspectOptions{}) |
| 223 | if err != nil { |
| 224 | return "", err |
| 225 | } |
| 226 | |
| 227 | taskName := fmt.Sprintf("%s.%d", serviceName, res.Task.Slot) |
| 228 | if !f.opts.noTaskIDs { |
| 229 | if f.opts.noTrunc { |
| 230 | taskName += "." + res.Task.ID |
| 231 | } else { |
| 232 | taskName += "." + formatter.TruncateID(res.Task.ID) |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | paddingCount := f.padding - getMaxLength(res.Task.Slot) |
| 237 | padding := "" |
| 238 | if paddingCount > 0 { |
| 239 | padding = strings.Repeat(" ", paddingCount) |
| 240 | } |
| 241 | formatted := taskName + "@" + nodeName + padding |
| 242 | f.cache[logCtx] = formatted |
| 243 | return formatted, nil |
| 244 | } |
| 245 | |
| 246 | type logWriter struct { |
| 247 | ctx context.Context |
no test coverage detected