Skip to content

Commit

Permalink
Adding config parameters for log rotation
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
  • Loading branch information
jaysheth2 committed Apr 11, 2024
1 parent 0b4b64f commit 396770b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ type Config struct {
// Flag to enable chaining with root program
BpfChainingEnabled bool

FileLogLocation string
FileLogLocation string
FileLogMaxSize int
FileLogMaxBackups int
FileLogMaxAge int

// stats
// Prometheus endpoint for pull/scrape the metrics.
Expand Down Expand Up @@ -108,6 +111,9 @@ func ReadConfig(configPath string) (*Config, error) {
MinKernelMajorVer: LoadOptionalConfigInt(confReader, "l3afd", "kernel-major-version", 5),
MinKernelMinorVer: LoadOptionalConfigInt(confReader, "l3afd", "kernel-minor-version", 15),
FileLogLocation: LoadOptionalConfigString(confReader, "l3afd", "file-log-location", ""),
FileLogMaxSize: LoadOptionalConfigInt(confReader, "l3afd", "file-log-max-size", 100),
FileLogMaxBackups: LoadOptionalConfigInt(confReader, "l3afd", "file-log-max-backups", 20),
FileLogMaxAge: LoadOptionalConfigInt(confReader, "l3afd", "file-log-max-age", 60),
EBPFRepoURL: LoadConfigString(confReader, "ebpf-repo", "url"),
HttpClientTimeout: LoadOptionalConfigDuration(confReader, "l3afd", "http-client-timeout", 30*time.Second),
MaxEBPFReStartCount: LoadOptionalConfigInt(confReader, "l3afd", "max-ebpf-restart-count", 3),
Expand Down
3 changes: 3 additions & 0 deletions docs/configdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ environment: PROD
|environment| `"PROD"` |If set to anything other than "PROD", mTLS security will not be checked| Yes |
|BpfMapDefaultPath| `"/sys/fs/bpf"` |The base pin path for eBPF maps| Yes |
| file-log-location | `"/var/log/l3afd.log"` | Location of the log file | No |
| file-log-max-size | `"100"` | Max size in megabytes for Log file rotation | No |
| file-log-max-backups | `"20"` | Max size in megabytes for Log file rotation | No |
| file-log-max-age | `"60"` | Max number of days to keep Log files | No |

## [ebpf-repo]
| FieldName | Default | Description | Required |
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func setupLogging() {
log.Debug().Msgf("Log level set to %q", logLevel)
}

func saveLogsToFile(confFileLogLocation string) {
func saveLogsToFile(conf *config.Config) {

logFileWithRotation := &lumberjack.Logger{
Filename: confFileLogLocation,
MaxSize: 100, // Max size in megabytes
MaxBackups: 20, // Max number of old log files to keep
MaxAge: 60, // Max number of days to keep log files
Filename: conf.FileLogLocation,
MaxSize: conf.FileLogMaxSize, // Max size in megabytes
MaxBackups: conf.FileLogMaxBackups, // Max number of old log files to keep
MaxAge: conf.FileLogMaxAge, // Max number of days to keep log files
}
multi := zerolog.MultiLevelWriter(os.Stdout, logFileWithRotation)
log.Logger = log.Output(zerolog.ConsoleWriter{
Expand All @@ -90,7 +90,7 @@ func main() {

if conf.FileLogLocation != "" {
log.Info().Msgf("Saving logs to file: %s", conf.FileLogLocation)
saveLogsToFile(conf.FileLogLocation)
saveLogsToFile(conf)
}

if err = pidfile.CheckPIDConflict(conf.PIDFilename); err != nil {
Expand Down

0 comments on commit 396770b

Please sign in to comment.