-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add the logs
subcommand to the CLI
#2745
Conversation
Following is supported: * Print the last `-n` lines of the logs (10 by default) * Follow the logs after printing * Filter logs by a component ID
🌐 Coverage report
|
filter = createComponentFilter(component) | ||
} | ||
|
||
logsDir := filepath.Join(paths.Home(), logger.DefaultLogDirectory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First I tried to use:
elastic-agent/internal/pkg/agent/application/paths/common.go
Lines 163 to 166 in cda5b7e
// Logs returns the log directory for Agent | |
func Logs() string { | |
return logsPath | |
} |
But (at least on Mac) it lead to /Library/Elastic/Agent
which had some logs but they were not actively updated while the agent was running.
After some digging, I found this line and copied from here:
elastic-agent/pkg/core/logger/logger.go
Lines 139 to 145 in cda5b7e
func MakeInternalFileOutput(cfg *Config) (zapcore.Core, error) { | |
// defaultCfg is used to set the defaults for the file rotation of the internal logging | |
// these settings cannot be changed by a user configuration | |
defaultCfg := logp.DefaultConfig(logp.DefaultEnvironment) | |
filename := filepath.Join(paths.Home(), DefaultLogDirectory, cfg.Beat) | |
al := zap.NewAtomicLevelAt(cfg.Level.ZapLevel()) | |
internalLevelEnabler = &al // directly persisting struct will panic on accessing unitialized backing pointer |
This seems to be the correct path for logs.
Can anyone explain why the logs are written in 2 different locations and confirm that this is the correct way to get the path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to @blakerouse the current location is the right location to watch for logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an optional small suggestion, otherwise LGTM
if !filter(line) { | ||
continue | ||
} | ||
_, _ = w.Write(line) | ||
_, _ = w.Write([]byte{'\n'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can flip the test here ?
if !filter(line) { | |
continue | |
} | |
_, _ = w.Write(line) | |
_, _ = w.Write([]byte{'\n'}) | |
if filter(line) { | |
_, _ = w.Write(line) | |
_, _ = w.Write([]byte{'\n'}) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm going to keep it as it is. I always prefer less indentation with a terminal if
.
Suggestion for future dev: could we add a |
tested on windows it works, all flags tested |
What does this PR do?
It adds the
logs
subcommand.Following is supported:
-n
lines of the logs (10 by default)Why is it important?
Improves development and troubleshooting experience.
Checklist
- [ ] I have made corresponding change to the default configuration files./changelog/fragments
using the changelog tool- [ ] I have added an integration test or an E2E testHow to test this PR locally
elastic-agent logs -f
Related issues
Screenshots
Screen.Recording.2023-05-30.at.15.27.23.mov