Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for saving the logs in a specified file #366

Merged
merged 10 commits into from Apr 15, 2024

Conversation

jaysheth2
Copy link
Contributor

Currently, L3AFD logs are only displayed on STDOUT. However, in some usecases, the logging and metrics framework might require the logs to be saved to persistent storage or discs. This PR add the functionality of allowing user to save logs to the file as well. The file includes log-rotation by default

@jaysheth2 jaysheth2 linked an issue Apr 4, 2024 that may be closed by this pull request
@jaysheth2 jaysheth2 force-pushed the jay-hv-fixlogging branch 2 times, most recently from 7190bb8 to 46f0bcd Compare April 4, 2024 21:06
Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
…xing docs

Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
@jaysheth2 jaysheth2 changed the title Adding support for saving the logs a specified file Adding support for saving the logs in a specified file Apr 5, 2024
@jaysheth2 jaysheth2 marked this pull request as ready for review April 5, 2024 06:01
config/config.go Outdated
@@ -105,6 +108,8 @@ func ReadConfig(configPath string) (*Config, error) {
BPFLogDir: LoadOptionalConfigString(confReader, "l3afd", "bpf-log-dir", ""),
MinKernelMajorVer: LoadOptionalConfigInt(confReader, "l3afd", "kernel-major-version", 5),
MinKernelMinorVer: LoadOptionalConfigInt(confReader, "l3afd", "kernel-minor-version", 15),
FileLogging: LoadOptionalConfigBool(confReader, "l3afd", "file-logging", false),
FileLogLocation: LoadOptionalConfigString(confReader, "l3afd", "file-log-location", "l3afd.log"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have one option that allows the program to write to a specific file path, "log-file-path: /var/log/l3afd.log", if it is provided? Otherwise, if no file path is specified, the program should follow the default behavior of not writing to a log file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
@@ -58,6 +59,20 @@ func setupLogging() {
log.Debug().Msgf("Log level set to %q", logLevel)
}

func saveLogsToFile(conf *config.Config) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can input only FileLogLocation instead of entire conf here.

config/l3afd.cfg Outdated
@@ -14,7 +14,7 @@ swagger-api-enabled: false
environment: PROD
# BpfMapDefaultPath is base path for storing maps
BpfMapDefaultPath: /sys/fs/bpf

file-log-location: l3afd.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the absolute file location path here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
sanfern
sanfern previously approved these changes Apr 8, 2024
Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
pmoroney
pmoroney previously approved these changes Apr 11, 2024
Copy link

@pmoroney pmoroney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one question inline

main.go Outdated

logFileWithRotation := &lumberjack.Logger{
Filename: confFileLogLocation,
MaxSize: 100, // Max size in megabytes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like log rotation, but are these parameters something that should be configurable by the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Added config parameters, that users can utilize to provide log rotation handles

Signed-off-by: Jay Sheth <jaykumar.sheth@walmart.com>
Copy link

@pmoroney pmoroney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@jaysheth2 jaysheth2 merged commit 7696478 into main Apr 15, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for saving L3AFD logs to a file
3 participants