Skip to content

Commit

Permalink
Set YAML Log File Path Correctly (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethAmazon authored Dec 6, 2023
1 parent cba127d commit 8d814c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func runAgent(ctx context.Context,

writer := logger.NewLogWriter(logConfig)

log.Printf("I! Starting AmazonCloudWatchAgent %s\n", version.Full())
log.Printf("I! Starting AmazonCloudWatchAgent %s with log file %s with log target %s\n", version.Full(), ag.Config.Agent.Logfile, ag.Config.Agent.LogTarget)
// Need to set SDK log level before plugins get loaded.
// Some aws.Config objects get created early and live forever which means
// we cannot change the sdk log level without restarting the Agent.
Expand Down
14 changes: 2 additions & 12 deletions translator/translate/otel/translate_otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.uber.org/zap/zapcore"

receiverAdapter "github.com/aws/amazon-cloudwatch-agent/receiver/adapter"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/agent"
"github.com/aws/amazon-cloudwatch-agent/translator/context"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/pipeline"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/pipeline/appsignals"
Expand Down Expand Up @@ -104,16 +104,6 @@ func Translate(jsonConfig interface{}, os string) (*otelcol.Config, error) {
return cfg, nil
}

// parseAgentLogFile returns the log file path form the JSON config, or the
// default value.
func parseAgentLogFile(conf *confmap.Conf) string {
v, ok := common.GetString(conf, common.ConfigKey("agent", "logfile"))
if !ok {
return agent.GetDefaultValue()
}
return v
}

// parseAgentLogLevel returns the logging level from the JSON config, or the
// default value.
func parseAgentLogLevel(conf *confmap.Conf) zapcore.Level {
Expand All @@ -133,7 +123,7 @@ func parseAgentLogLevel(conf *confmap.Conf) zapcore.Level {
// logging configuration that should go in the YAML.
func getLoggingConfig(conf *confmap.Conf) telemetry.LogsConfig {
var outputPaths []string
filename := parseAgentLogFile(conf)
filename := context.CurrentContext().GetAgentLogFile()
// A slice with an empty string causes OTEL issues, so avoid it.
if filename != "" {
outputPaths = []string{filename}
Expand Down

0 comments on commit 8d814c7

Please sign in to comment.