Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libbeat/logp/configure/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func Logging(beatName string, cfg *common.Config) error {
return err
}
}

if config.Files.Name == "" && config.ToFiles {
config.Files.Name = beatName
}
applyFlags(&config)
return logp.Configure(config)
}
Expand Down
13 changes: 8 additions & 5 deletions libbeat/logp/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ func makeOptions(cfg Config) []zap.Option {
if cfg.development {
options = append(options, zap.Development())
}
if cfg.ECSEnabled {
fields := []zap.Field{zap.String("service.name", cfg.Beat)}
if cfg.Files.Name != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I see why this works, but it looks wrong to me since we should add event.dataset for non-file logging output. How about we introduce a new function in this package like

// logFilename returns the base filename to which logs will be written for
// the "files" log output. If another log output is used, or `logging.files.name`
// is unspecified, then the beat name will be returned.
func logFilename(cfg Config) string {
    name := cfg.Beat
    if cfg.Files.Name != "" {
        name = cfg.Files.Name
    }
    return name
}

Then you can use that here and in makeFileOutput, and revert the configure.Logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should add event.dataset for non-file logging output

I don't get that. If the output is eg. stderr what should be the value of event.dataset?

Copy link
Member

Choose a reason for hiding this comment

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

See #25997 and https://github.com/elastic/ecs-logging/blob/9507c12f7523741cc06f84a2686d580e50f3465f/spec/spec.json#L79-L95

If the user manually configures the service name, the logging library should set event.dataset=${service.name}.log if not explicitly configured otherwise.

fields = append(fields, zap.String("event.dataset", cfg.Files.Name))
}
options = append(options, zap.Fields(fields...))
}
return options
}

Expand Down Expand Up @@ -226,11 +233,7 @@ func makeEventLogOutput(cfg Config) (zapcore.Core, error) {
}

func makeFileOutput(cfg Config) (zapcore.Core, error) {
name := cfg.Beat
if cfg.Files.Name != "" {
name = cfg.Files.Name
}
filename := paths.Resolve(paths.Logs, filepath.Join(cfg.Files.Path, name))
filename := paths.Resolve(paths.Logs, filepath.Join(cfg.Files.Path, cfg.Files.Name))

rotator, err := file.NewFileRotator(filename,
file.MaxSizeBytes(cfg.Files.MaxSize),
Expand Down