diff --git a/agent/app/run.go b/agent/app/run.go index e6fdb37ca32..0ee12573c40 100644 --- a/agent/app/run.go +++ b/agent/app/run.go @@ -60,9 +60,11 @@ func Run(arguments []string) int { } if *parsedArgs.LogLevel != "" { - logger.SetLevel(*parsedArgs.LogLevel, *parsedArgs.LogLevel) + logger.SetDriverLogLevel(*parsedArgs.LogLevel) + logger.SetInstanceLogLevel(*parsedArgs.LogLevel) } else { - logger.SetLevel(*parsedArgs.DriverLogLevel, *parsedArgs.InstanceLogLevel) + logger.SetDriverLogLevel(*parsedArgs.DriverLogLevel) + logger.SetInstanceLogLevel(*parsedArgs.InstanceLogLevel) } // Create an Agent object diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/logger/log.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/logger/log.go index fc7025f823c..3bc9bc54762 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/logger/log.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/logger/log.go @@ -44,8 +44,19 @@ const ( DEFAULT_TIMESTAMP_FORMAT = time.RFC3339 DEFAULT_MAX_FILE_SIZE float64 = 10 DEFAULT_MAX_ROLL_COUNT int = 24 + DEFAULT_LOGTO_STDOUT = true ) +// logLevels is the mapping from ECS_LOGLEVEL to Seelog provided levels. +var logLevels = map[string]string{ + "debug": "debug", + "info": "info", + "warn": "warn", + "error": "error", + "crit": "critical", + "none": "off", +} + type logConfig struct { RolloverType string MaxRollCount int @@ -55,6 +66,7 @@ type logConfig struct { instanceLevel string outputFormat string timestampFormat string + logToStdout bool lock sync.Mutex } @@ -144,14 +156,21 @@ func reloadConfig() { } func seelogConfig() string { + platformLogConfig := platformLogConfig() c := ` - + ` + if platformLogConfig != "" || Config.logToStdout { + c += ` - ` - c += platformLogConfig() - c += ` + ` + if Config.logToStdout { + c += ` ` + } + c += platformLogConfig + c += ` ` + } if Config.logfile != "" { c += ` ` @@ -159,10 +178,13 @@ func seelogConfig() string { c += ` ` - } else { + } else if Config.RolloverType == "date" { c += ` ` + } else { + c += ` + ` } c += ` ` @@ -191,33 +213,6 @@ func getLevelList(fileLevel string) string { return levelLists[fileLevel] } -// SetLevel sets the log levels for logging -func SetLevel(driverLogLevel, instanceLogLevel string) { - levels := map[string]string{ - "debug": "debug", - "info": "info", - "warn": "warn", - "error": "error", - "crit": "critical", - "none": "off", - } - - parsedDriverLevel, driverOk := levels[strings.ToLower(driverLogLevel)] - parsedInstanceLevel, instanceOk := levels[strings.ToLower(instanceLogLevel)] - - if instanceOk || driverOk { - Config.lock.Lock() - defer Config.lock.Unlock() - if instanceOk { - Config.instanceLevel = parsedInstanceLevel - } - if driverOk { - Config.driverLevel = parsedDriverLevel - } - reloadConfig() - } -} - // GetLevel gets the log level func GetLevel() string { Config.lock.Lock() @@ -236,12 +231,43 @@ func setInstanceLevelDefault() string { return DEFAULT_LOGLEVEL } +// SetInstanceLogLevel explicitly sets the log level for instance logs. +func SetInstanceLogLevel(instanceLogLevel string) { + parsedLevel, ok := logLevels[strings.ToLower(instanceLogLevel)] + if ok { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.instanceLevel = parsedLevel + reloadConfig() + } else { + seelog.Error("Instance log level mapping not found") + } +} + +// SetDriverLogLevel explicitly sets the log level for a custom driver. +func SetDriverLogLevel(driverLogLevel string) { + parsedLevel, ok := logLevels[strings.ToLower(driverLogLevel)] + if ok { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.driverLevel = parsedLevel + reloadConfig() + } else { + seelog.Error("Driver log level mapping not found") + } +} + // SetConfigLogFile sets the default output file of the logger. func SetConfigLogFile(logFile string) { - Config.lock.Lock() - defer Config.lock.Unlock() + if logFile != "" { + Config.lock.Lock() + defer Config.lock.Unlock() - Config.logfile = logFile + Config.logfile = logFile + reloadConfig() + } } // SetConfigLogFormat sets the output format of the logger. @@ -250,20 +276,33 @@ func SetConfigLogFormat(logFormat string) { Config.lock.Lock() defer Config.lock.Unlock() - os.Setenv(LOG_OUTPUT_FORMAT_ENV_VAR, logFormat) Config.outputFormat = logFormat + reloadConfig() } // SetConfigMaxFileSizeMB sets the max file size of a log file // in Megabytes before the logger rotates to a new file. func SetConfigMaxFileSizeMB(maxSizeInMB float64) { - Config.lock.Lock() - defer Config.lock.Unlock() + if maxSizeInMB > 0 { + Config.lock.Lock() + defer Config.lock.Unlock() - // Parse unit as string to set as environment variable. - strsize := strconv.FormatFloat(maxSizeInMB, 'f', -1, 64) - os.Setenv(LOG_MAX_FILE_SIZE_ENV_VAR, strsize) - Config.MaxFileSizeMB = maxSizeInMB + Config.MaxFileSizeMB = maxSizeInMB + reloadConfig() + } +} + +// SetRolloverType sets the logging rollover constraint. +// This should be either size or date. Logger will roll +// to a new log file based on this constraint. +func SetRolloverType(rolloverType string) { + if rolloverType == "date" || rolloverType == "size" { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.RolloverType = rolloverType + reloadConfig() + } } // SetTimestampFormat sets the time formatting @@ -271,14 +310,26 @@ func SetConfigMaxFileSizeMB(maxSizeInMB float64) { // a valid time format such as time.RFC3339 // or "2006-01-02T15:04:05.000". func SetTimestampFormat(format string) { - Config.lock.Lock() - defer Config.lock.Unlock() - if format != "" { + Config.lock.Lock() + defer Config.lock.Unlock() + Config.timestampFormat = format + reloadConfig() } } +// SetlogToStdout decides whether the logger +// should write to stdout using the tag +// in addition to logfiles that are set up. +func SetlogToStdout(duplicate bool) { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.logToStdout = duplicate + reloadConfig() +} + func init() { Config = &logConfig{ logfile: os.Getenv(LOGFILE_ENV_VAR), @@ -289,9 +340,13 @@ func init() { MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, timestampFormat: DEFAULT_TIMESTAMP_FORMAT, + logToStdout: DEFAULT_LOGTO_STDOUT, } } +// InitSeelog registers custom logging formats, updates the internal Config struct +// and reloads the global logger. This should only be called once, as external +// callers should use the Config struct over environment variables directly. func InitSeelog() { if err := seelog.RegisterCustomFormatter("EcsAgentLogfmt", logfmtFormatter); err != nil { seelog.Error(err) @@ -303,8 +358,12 @@ func InitSeelog() { seelog.Error(err) } - SetLevel(os.Getenv(LOGLEVEL_ENV_VAR), os.Getenv(LOGLEVEL_ON_INSTANCE_ENV_VAR)) - + if DriverLogLevel := os.Getenv(LOGLEVEL_ENV_VAR); DriverLogLevel != "" { + SetDriverLogLevel(DriverLogLevel) + } + if InstanceLogLevel := os.Getenv(LOGLEVEL_ON_INSTANCE_ENV_VAR); InstanceLogLevel != "" { + SetInstanceLogLevel(InstanceLogLevel) + } if RolloverType := os.Getenv(LOG_ROLLOVER_TYPE_ENV_VAR); RolloverType != "" { Config.RolloverType = RolloverType } diff --git a/ecs-agent/logger/log.go b/ecs-agent/logger/log.go index fc7025f823c..3bc9bc54762 100644 --- a/ecs-agent/logger/log.go +++ b/ecs-agent/logger/log.go @@ -44,8 +44,19 @@ const ( DEFAULT_TIMESTAMP_FORMAT = time.RFC3339 DEFAULT_MAX_FILE_SIZE float64 = 10 DEFAULT_MAX_ROLL_COUNT int = 24 + DEFAULT_LOGTO_STDOUT = true ) +// logLevels is the mapping from ECS_LOGLEVEL to Seelog provided levels. +var logLevels = map[string]string{ + "debug": "debug", + "info": "info", + "warn": "warn", + "error": "error", + "crit": "critical", + "none": "off", +} + type logConfig struct { RolloverType string MaxRollCount int @@ -55,6 +66,7 @@ type logConfig struct { instanceLevel string outputFormat string timestampFormat string + logToStdout bool lock sync.Mutex } @@ -144,14 +156,21 @@ func reloadConfig() { } func seelogConfig() string { + platformLogConfig := platformLogConfig() c := ` - + ` + if platformLogConfig != "" || Config.logToStdout { + c += ` - ` - c += platformLogConfig() - c += ` + ` + if Config.logToStdout { + c += ` ` + } + c += platformLogConfig + c += ` ` + } if Config.logfile != "" { c += ` ` @@ -159,10 +178,13 @@ func seelogConfig() string { c += ` ` - } else { + } else if Config.RolloverType == "date" { c += ` ` + } else { + c += ` + ` } c += ` ` @@ -191,33 +213,6 @@ func getLevelList(fileLevel string) string { return levelLists[fileLevel] } -// SetLevel sets the log levels for logging -func SetLevel(driverLogLevel, instanceLogLevel string) { - levels := map[string]string{ - "debug": "debug", - "info": "info", - "warn": "warn", - "error": "error", - "crit": "critical", - "none": "off", - } - - parsedDriverLevel, driverOk := levels[strings.ToLower(driverLogLevel)] - parsedInstanceLevel, instanceOk := levels[strings.ToLower(instanceLogLevel)] - - if instanceOk || driverOk { - Config.lock.Lock() - defer Config.lock.Unlock() - if instanceOk { - Config.instanceLevel = parsedInstanceLevel - } - if driverOk { - Config.driverLevel = parsedDriverLevel - } - reloadConfig() - } -} - // GetLevel gets the log level func GetLevel() string { Config.lock.Lock() @@ -236,12 +231,43 @@ func setInstanceLevelDefault() string { return DEFAULT_LOGLEVEL } +// SetInstanceLogLevel explicitly sets the log level for instance logs. +func SetInstanceLogLevel(instanceLogLevel string) { + parsedLevel, ok := logLevels[strings.ToLower(instanceLogLevel)] + if ok { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.instanceLevel = parsedLevel + reloadConfig() + } else { + seelog.Error("Instance log level mapping not found") + } +} + +// SetDriverLogLevel explicitly sets the log level for a custom driver. +func SetDriverLogLevel(driverLogLevel string) { + parsedLevel, ok := logLevels[strings.ToLower(driverLogLevel)] + if ok { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.driverLevel = parsedLevel + reloadConfig() + } else { + seelog.Error("Driver log level mapping not found") + } +} + // SetConfigLogFile sets the default output file of the logger. func SetConfigLogFile(logFile string) { - Config.lock.Lock() - defer Config.lock.Unlock() + if logFile != "" { + Config.lock.Lock() + defer Config.lock.Unlock() - Config.logfile = logFile + Config.logfile = logFile + reloadConfig() + } } // SetConfigLogFormat sets the output format of the logger. @@ -250,20 +276,33 @@ func SetConfigLogFormat(logFormat string) { Config.lock.Lock() defer Config.lock.Unlock() - os.Setenv(LOG_OUTPUT_FORMAT_ENV_VAR, logFormat) Config.outputFormat = logFormat + reloadConfig() } // SetConfigMaxFileSizeMB sets the max file size of a log file // in Megabytes before the logger rotates to a new file. func SetConfigMaxFileSizeMB(maxSizeInMB float64) { - Config.lock.Lock() - defer Config.lock.Unlock() + if maxSizeInMB > 0 { + Config.lock.Lock() + defer Config.lock.Unlock() - // Parse unit as string to set as environment variable. - strsize := strconv.FormatFloat(maxSizeInMB, 'f', -1, 64) - os.Setenv(LOG_MAX_FILE_SIZE_ENV_VAR, strsize) - Config.MaxFileSizeMB = maxSizeInMB + Config.MaxFileSizeMB = maxSizeInMB + reloadConfig() + } +} + +// SetRolloverType sets the logging rollover constraint. +// This should be either size or date. Logger will roll +// to a new log file based on this constraint. +func SetRolloverType(rolloverType string) { + if rolloverType == "date" || rolloverType == "size" { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.RolloverType = rolloverType + reloadConfig() + } } // SetTimestampFormat sets the time formatting @@ -271,14 +310,26 @@ func SetConfigMaxFileSizeMB(maxSizeInMB float64) { // a valid time format such as time.RFC3339 // or "2006-01-02T15:04:05.000". func SetTimestampFormat(format string) { - Config.lock.Lock() - defer Config.lock.Unlock() - if format != "" { + Config.lock.Lock() + defer Config.lock.Unlock() + Config.timestampFormat = format + reloadConfig() } } +// SetlogToStdout decides whether the logger +// should write to stdout using the tag +// in addition to logfiles that are set up. +func SetlogToStdout(duplicate bool) { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.logToStdout = duplicate + reloadConfig() +} + func init() { Config = &logConfig{ logfile: os.Getenv(LOGFILE_ENV_VAR), @@ -289,9 +340,13 @@ func init() { MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, timestampFormat: DEFAULT_TIMESTAMP_FORMAT, + logToStdout: DEFAULT_LOGTO_STDOUT, } } +// InitSeelog registers custom logging formats, updates the internal Config struct +// and reloads the global logger. This should only be called once, as external +// callers should use the Config struct over environment variables directly. func InitSeelog() { if err := seelog.RegisterCustomFormatter("EcsAgentLogfmt", logfmtFormatter); err != nil { seelog.Error(err) @@ -303,8 +358,12 @@ func InitSeelog() { seelog.Error(err) } - SetLevel(os.Getenv(LOGLEVEL_ENV_VAR), os.Getenv(LOGLEVEL_ON_INSTANCE_ENV_VAR)) - + if DriverLogLevel := os.Getenv(LOGLEVEL_ENV_VAR); DriverLogLevel != "" { + SetDriverLogLevel(DriverLogLevel) + } + if InstanceLogLevel := os.Getenv(LOGLEVEL_ON_INSTANCE_ENV_VAR); InstanceLogLevel != "" { + SetInstanceLogLevel(InstanceLogLevel) + } if RolloverType := os.Getenv(LOG_ROLLOVER_TYPE_ENV_VAR); RolloverType != "" { Config.RolloverType = RolloverType } diff --git a/ecs-agent/logger/log_test.go b/ecs-agent/logger/log_test.go index 2881a0b9b34..9527f83aad2 100644 --- a/ecs-agent/logger/log_test.go +++ b/ecs-agent/logger/log_test.go @@ -142,7 +142,7 @@ func TestJSONFormat_Structured_Timestamp(t *testing.T) { require.JSONEq(t, `{"level": "debug", "time": "2018-10-01T01:02:03.000", "msg": "This is my log message"}`, s) } -func TestSetLevel(t *testing.T) { +func TestSetLogLevels(t *testing.T) { resetEnv := func() { os.Unsetenv(LOGLEVEL_ENV_VAR) os.Unsetenv(LOGLEVEL_ON_INSTANCE_ENV_VAR) @@ -232,6 +232,8 @@ func TestSetLevel(t *testing.T) { os.Setenv(LOGLEVEL_ON_INSTANCE_ENV_VAR, test.loglevelInstance) os.Setenv(LOG_DRIVER_ENV_VAR, test.logDriver) + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, @@ -241,8 +243,10 @@ func TestSetLevel(t *testing.T) { MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } - SetLevel(os.Getenv(LOGLEVEL_ENV_VAR), os.Getenv(LOGLEVEL_ON_INSTANCE_ENV_VAR)) + + SetDriverLogLevel(test.loglevel) require.Equal(t, test.expectedLoglevel, Config.driverLevel) + SetInstanceLogLevel(test.loglevelInstance) require.Equal(t, test.expectedLoglevelInstance, Config.instanceLevel) }) } diff --git a/ecs-agent/logger/log_unix_test.go b/ecs-agent/logger/log_unix_test.go index 0b063d1837b..60e8667387b 100644 --- a/ecs-agent/logger/log_unix_test.go +++ b/ecs-agent/logger/log_unix_test.go @@ -24,6 +24,8 @@ import ( ) func TestSeelogConfig_Default(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, @@ -32,6 +34,7 @@ func TestSeelogConfig_Default(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -54,6 +57,8 @@ func TestSeelogConfig_Default(t *testing.T) { } func TestSeelogConfig_WithoutLogFile(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, @@ -61,6 +66,7 @@ func TestSeelogConfig_WithoutLogFile(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -78,7 +84,38 @@ func TestSeelogConfig_WithoutLogFile(t *testing.T) { `, c) } +func TestSeeLogConfig_WithoutStdout(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() + Config = &logConfig{ + logfile: "foo.log", + driverLevel: DEFAULT_LOGLEVEL, + instanceLevel: DEFAULT_LOGLEVEL, + RolloverType: "none", + outputFormat: DEFAULT_OUTPUT_FORMAT, + MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, + MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: false, + } + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + +`, c) +} + func TestSeelogConfig_DebugLevel(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: "debug", @@ -87,6 +124,7 @@ func TestSeelogConfig_DebugLevel(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -109,6 +147,8 @@ func TestSeelogConfig_DebugLevel(t *testing.T) { } func TestSeelogConfig_SizeRollover(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, @@ -117,6 +157,7 @@ func TestSeelogConfig_SizeRollover(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -139,6 +180,8 @@ func TestSeelogConfig_SizeRollover(t *testing.T) { } func TestSeelogConfig_SizeRolloverFileSizeChange(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, @@ -147,6 +190,7 @@ func TestSeelogConfig_SizeRolloverFileSizeChange(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -169,6 +213,8 @@ func TestSeelogConfig_SizeRolloverFileSizeChange(t *testing.T) { } func TestSeelogConfig_SizeRolloverRollCountChange(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, @@ -177,6 +223,7 @@ func TestSeelogConfig_SizeRolloverRollCountChange(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: 10, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -199,6 +246,8 @@ func TestSeelogConfig_SizeRolloverRollCountChange(t *testing.T) { } func TestSeelogConfig_JSONOutput(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, @@ -207,6 +256,7 @@ func TestSeelogConfig_JSONOutput(t *testing.T) { outputFormat: "json", MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: 10, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -228,7 +278,71 @@ func TestSeelogConfig_JSONOutput(t *testing.T) { `, c) } +func TestSeelogConfig_JSONNoStdout(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() + Config = &logConfig{ + logfile: "foo.log", + driverLevel: DEFAULT_LOGLEVEL, + instanceLevel: DEFAULT_LOGLEVEL, + RolloverType: DEFAULT_ROLLOVER_TYPE, + outputFormat: "json", + MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, + MaxRollCount: 10, + logToStdout: false, + } + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + +`, c) +} + +func TestSeelogConfig_JSONNoRollover(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() + Config = &logConfig{ + logfile: "foo.log", + driverLevel: DEFAULT_LOGLEVEL, + instanceLevel: DEFAULT_LOGLEVEL, + RolloverType: "none", + outputFormat: "json", + MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, + MaxRollCount: 10, + logToStdout: DEFAULT_LOGTO_STDOUT, + } + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + + + + +`, c) +} + func TestSeelogConfig_NoOnInstanceLog(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, @@ -237,6 +351,7 @@ func TestSeelogConfig_NoOnInstanceLog(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -259,6 +374,8 @@ func TestSeelogConfig_NoOnInstanceLog(t *testing.T) { } func TestSeelogConfig_DifferentLevels(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() Config = &logConfig{ logfile: "foo.log", driverLevel: "warn", @@ -267,6 +384,7 @@ func TestSeelogConfig_DifferentLevels(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -289,6 +407,8 @@ func TestSeelogConfig_DifferentLevels(t *testing.T) { } func TestSeelogConfig_FileLevelDefault(t *testing.T) { + Config.lock.Lock() + defer Config.lock.Unlock() os.Setenv(LOG_DRIVER_ENV_VAR, "awslogs") defer os.Unsetenv(LOG_DRIVER_ENV_VAR) @@ -300,6 +420,7 @@ func TestSeelogConfig_FileLevelDefault(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` diff --git a/ecs-agent/logger/log_windows_test.go b/ecs-agent/logger/log_windows_test.go index c763d595ac8..8dcd5fe4369 100644 --- a/ecs-agent/logger/log_windows_test.go +++ b/ecs-agent/logger/log_windows_test.go @@ -32,6 +32,7 @@ func TestSeelogConfigWindows_Default(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -62,6 +63,7 @@ func TestSeelogConfigWindows_WithoutLogFile(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -89,6 +91,7 @@ func TestSeelogConfigWindows_DebugLevel(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -120,6 +123,7 @@ func TestSeelogConfigWindows_SizeRollover(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -151,6 +155,7 @@ func TestSeelogConfigWindows_SizeRolloverFileSizeChange(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -182,6 +187,7 @@ func TestSeelogConfigWindows_SizeRolloverRollCountChange(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: 10, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -213,6 +219,7 @@ func TestSeelogConfigWindows_JSONOutput(t *testing.T) { outputFormat: "json", MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: 10, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -244,6 +251,7 @@ func TestSeelogConfigWindows_NoOnInstanceLog(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -275,6 +283,7 @@ func TestSeelogConfigWindows_DifferentLevels(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -309,6 +318,7 @@ func TestSeelogConfigWindows_FileLevelDefault(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, `