Skip to content

Commit

Permalink
Initialize logger directory to allow group access (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioalvap authored May 19, 2022
1 parent 42c2c1b commit acc6013
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions internal/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,13 @@ func setPaths(statePath, configPath, logsPath string, writePaths bool) error {
return fmt.Errorf("preparing LOGS_PATH(%s) failed: %w", logsPath, err)
}
}

// ensure that the internal logger directory exists
loggerPath := filepath.Join(paths.Home(), logger.DefaultLogDirectory)
if err := os.MkdirAll(loggerPath, 0755); err != nil {
return fmt.Errorf("preparing internal log path(%s) failed: %w", loggerPath, err)
}

// persist the paths so other commands in the container will use the correct paths
if writePaths {
if err := writeContainerPaths(originalTop, statePath, configPath, logsPath); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/core/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const iso8601Format = "2006-01-02T15:04:05.000Z0700"
// DefaultLogLevel used in agent and its processes.
const DefaultLogLevel = logp.InfoLevel

// DefaultLogDirectory used in agent and its processes.
const DefaultLogDirectory = "logs"

// Logger alias ecslog.Logger with Logger.
type Logger = logp.Logger

Expand Down Expand Up @@ -114,7 +117,7 @@ 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(), "logs", cfg.Beat)
filename := filepath.Join(paths.Home(), DefaultLogDirectory, cfg.Beat)

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

0 comments on commit acc6013

Please sign in to comment.