Add a new FSHook to the logger. Each component will log in its own file
(hook config.LogrusHook, level logrus.Level, componentName string)
| 121 | |
| 122 | // Add a new FSHook to the logger. Each component will log in its own file |
| 123 | func setupFileHook(hook config.LogrusHook, level logrus.Level, componentName string) { |
| 124 | dirPath := (hook.Params["path"]).(string) |
| 125 | fullPath := filepath.Join(dirPath, componentName+".log") |
| 126 | |
| 127 | if err := os.MkdirAll(path.Dir(fullPath), os.ModePerm); err != nil { |
| 128 | logrus.Fatalf("Couldn't create directory %s: %q", path.Dir(fullPath), err) |
| 129 | } |
| 130 | |
| 131 | logrus.AddHook(&logLevelHook{ |
| 132 | level, |
| 133 | dugong.NewFSHook( |
| 134 | fullPath, |
| 135 | &utcFormatter{ |
| 136 | &logrus.TextFormatter{ |
| 137 | TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00", |
| 138 | DisableColors: true, |
| 139 | DisableTimestamp: false, |
| 140 | DisableSorting: false, |
| 141 | QuoteEmptyFields: true, |
| 142 | }, |
| 143 | }, |
| 144 | &dugong.DailyRotationSchedule{GZip: true}, |
| 145 | ), |
| 146 | }) |
| 147 | } |
| 148 | |
| 149 | // CloseAndLogIfError Closes io.Closer and logs the error if any |
| 150 | func CloseAndLogIfError(ctx context.Context, closer io.Closer, message string) { |
no outgoing calls
no test coverage detected