(ctx context.Context, dataStore string, config *logging.Config)
| 82 | } |
| 83 | |
| 84 | func (jsonLogger *JSONLogger) PreProcess(ctx context.Context, dataStore string, config *logging.Config) error { |
| 85 | var jsonFilePath string |
| 86 | if logPath, ok := jsonLogger.Opts[LogPath]; ok { |
| 87 | jsonFilePath = logPath |
| 88 | } else { |
| 89 | jsonFilePath = jsonfile.Path(dataStore, config.Namespace, config.ID) |
| 90 | } |
| 91 | l := &logrotate.Logger{ |
| 92 | Filename: jsonFilePath, |
| 93 | } |
| 94 | // MaxBytes is the maximum size in bytes of the log file before it gets |
| 95 | // rotated. If not set, it defaults to 100 MiB. |
| 96 | // see: https://github.com/fahedouch/go-logrotate/blob/6a8beddaea39b2b9c77109d7fa2fe92053c063e5/logrotate.go#L500 |
| 97 | if capacity, ok := jsonLogger.Opts[MaxSize]; ok { |
| 98 | var capVal int64 |
| 99 | var err error |
| 100 | capVal, err = units.FromHumanSize(capacity) |
| 101 | if err != nil { |
| 102 | return err |
| 103 | } |
| 104 | if capVal <= 0 { |
| 105 | return fmt.Errorf("max-size must be a positive number") |
| 106 | } |
| 107 | l.MaxBytes = capVal |
| 108 | } |
| 109 | maxFile := 1 |
| 110 | if maxFileString, ok := jsonLogger.Opts[MaxFile]; ok { |
| 111 | var err error |
| 112 | maxFile, err = strconv.Atoi(maxFileString) |
| 113 | if err != nil { |
| 114 | return err |
| 115 | } |
| 116 | if maxFile < 1 { |
| 117 | return fmt.Errorf("max-file cannot be less than 1") |
| 118 | } |
| 119 | } |
| 120 | // MaxBackups does not include file to write logs to |
| 121 | l.MaxBackups = maxFile - 1 |
| 122 | jsonLogger.logger = l |
| 123 | jsonLogger.encoder = jsonfile.NewSyncEncoder(l) |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | func (jsonLogger *JSONLogger) Process(stdout <-chan string, stderr <-chan string) error { |
| 128 | return jsonfile.Encode(stdout, stderr, jsonLogger.logger) |
nothing calls this directly
no test coverage detected