(context *cli.Context)
| 192 | } |
| 193 | |
| 194 | func configLogrus(context *cli.Context) error { |
| 195 | if context.GlobalBool("debug") { |
| 196 | logrus.SetLevel(logrus.DebugLevel) |
| 197 | logrus.SetReportCaller(true) |
| 198 | // Shorten function and file names reported by the logger, by |
| 199 | // trimming common "github.com/opencontainers/runc" prefix. |
| 200 | // This is only done for text formatter. |
| 201 | _, file, _, _ := runtime.Caller(0) |
| 202 | prefix := filepath.Dir(file) + "/" |
| 203 | logrus.SetFormatter(&logrus.TextFormatter{ |
| 204 | CallerPrettyfier: func(f *runtime.Frame) (string, string) { |
| 205 | function := strings.TrimPrefix(f.Function, prefix) + "()" |
| 206 | fileLine := strings.TrimPrefix(f.File, prefix) + ":" + strconv.Itoa(f.Line) |
| 207 | return function, fileLine |
| 208 | }, |
| 209 | }) |
| 210 | } |
| 211 | |
| 212 | switch f := context.GlobalString("log-format"); f { |
| 213 | case "": |
| 214 | // do nothing |
| 215 | case "text": |
| 216 | // do nothing |
| 217 | case "json": |
| 218 | logrus.SetFormatter(new(logrus.JSONFormatter)) |
| 219 | default: |
| 220 | return errors.New("invalid log-format: " + f) |
| 221 | } |
| 222 | |
| 223 | if file := context.GlobalString("log"); file != "" { |
| 224 | f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0o644) |
| 225 | if err != nil { |
| 226 | return err |
| 227 | } |
| 228 | logrus.SetOutput(f) |
| 229 | } |
| 230 | |
| 231 | return nil |
| 232 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…