Skip to content

Commit

Permalink
Agent naming (#330)
Browse files Browse the repository at this point in the history
* Add Metadata.name to Agent config
* Use metadata.name to give the Agent a name
* Add the AgentName parameter to all log entries
* This is useful for being to filter the logs associated with a
particular experiment.

Fix #280

---------

Co-authored-by: Jeremy Lewi <jeremy+github@lewi.us>
Co-authored-by: standard-input[bot] <183254018+standard-input[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent 3f8fa1a commit 06da767
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/pkg/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ func (a *App) SetupLogging(logToFile bool) error {
newLogger := zap.New(core)
// Record the caller of the log message
newLogger = newLogger.WithOptions(zap.AddCaller())
newLogger = newLogger.With(zap.String("agentName", a.Config.Metadata.Name))
zap.ReplaceGlobals(newLogger)

return nil
}

Expand Down
10 changes: 10 additions & 0 deletions app/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type Config struct {

// configFile is the configuration file used. It is
configFile string

Metadata api.Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

type LearnerConfig struct {
Expand Down Expand Up @@ -223,6 +225,14 @@ func (c *Config) GetModel() string {
return c.Agent.Model
}

// GetAgentName returns the name of the agent from the configuration.
func (c *Config) GetAgentName() string {
if c.Metadata.Name == "" {
return ""
}
return c.Metadata.Name
}

func (c *Config) GetLogDir() string {
if c.Logging.LogDir != "" {
return c.Logging.LogDir
Expand Down

0 comments on commit 06da767

Please sign in to comment.