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..5044a3e74e7 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,18 +44,34 @@ const ( DEFAULT_TIMESTAMP_FORMAT = time.RFC3339 DEFAULT_MAX_FILE_SIZE float64 = 10 DEFAULT_MAX_ROLL_COUNT int = 24 + DEFAULT_LOGTO_STDOUT = true ) +// Because timestamp format will be called in the custom formatter +// for each log message processed, it should not be handled +// with an explicitly write protected configuration. +var timestampFormat = DEFAULT_TIMESTAMP_FORMAT + +// 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 - MaxFileSizeMB float64 - logfile string - driverLevel string - instanceLevel string - outputFormat string - timestampFormat string - lock sync.Mutex + RolloverType string + MaxRollCount int + MaxFileSizeMB float64 + logfile string + driverLevel string + instanceLevel string + outputFormat string + logToStdout bool + lock sync.Mutex } var Config *logConfig @@ -89,7 +105,7 @@ func logfmtFormatter(params string) seelog.FormatterFunc { buf.WriteString(level.String()) buf.WriteByte(' ') buf.WriteString("time=") - buf.WriteString(context.CallTime().UTC().Format(Config.timestampFormat)) + buf.WriteString(context.CallTime().UTC().Format(timestampFormat)) buf.WriteByte(' ') // temporary measure to make this change backwards compatible as we update to structured logs if strings.HasPrefix(message, structuredTxtFormatPrefix) { @@ -114,7 +130,7 @@ func jsonFormatter(params string) seelog.FormatterFunc { buf.WriteString(`{"level":"`) buf.WriteString(level.String()) buf.WriteString(`","time":"`) - buf.WriteString(context.CallTime().UTC().Format(Config.timestampFormat)) + buf.WriteString(context.CallTime().UTC().Format(timestampFormat)) buf.WriteString(`",`) // temporary measure to make this change backwards compatible as we update to structured logs if strings.HasPrefix(message, structuredJsonFormatPrefix) { @@ -144,14 +160,26 @@ func reloadConfig() { } func seelogConfig() string { + driverLogChildren := []string{} + platformLogConfig := platformLogConfig() + if Config.logToStdout { + driverLogChildren = append(driverLogChildren, ` `) + } + if platformLogConfig != "" { + driverLogChildren = append(driverLogChildren, platformLogConfig) + } + c := ` - + ` + if len(driverLogChildren) > 0 { + c += ` - ` - c += platformLogConfig() - c += ` + ` + c += strings.Join(driverLogChildren, "\n") + c += ` ` + } if Config.logfile != "" { c += ` ` @@ -159,6 +187,9 @@ func seelogConfig() string { c += ` ` + } else if Config.RolloverType == "none" { + c += ` + ` } else { c += ` 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() + } else { + seelog.Error("Invalid Max File Size Provided") + } +} + +// 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" || rolloverType == "none" { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.RolloverType = rolloverType + reloadConfig() + } else { + seelog.Error("Invalid log rollover type provided") + } } // SetTimestampFormat sets the time formatting @@ -271,27 +323,38 @@ func SetConfigMaxFileSizeMB(maxSizeInMB float64) { // a valid time format such as time.RFC3339 // or "2006-01-02T15:04:05.000". func SetTimestampFormat(format string) { + if format != "" { + timestampFormat = format + } +} + +// 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() - if format != "" { - Config.timestampFormat = format - } + Config.logToStdout = duplicate + reloadConfig() } func init() { Config = &logConfig{ - logfile: os.Getenv(LOGFILE_ENV_VAR), - driverLevel: DEFAULT_LOGLEVEL, - instanceLevel: setInstanceLevelDefault(), - RolloverType: DEFAULT_ROLLOVER_TYPE, - outputFormat: DEFAULT_OUTPUT_FORMAT, - MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, - MaxRollCount: DEFAULT_MAX_ROLL_COUNT, - timestampFormat: DEFAULT_TIMESTAMP_FORMAT, + logfile: os.Getenv(LOGFILE_ENV_VAR), + driverLevel: DEFAULT_LOGLEVEL, + instanceLevel: setInstanceLevelDefault(), + RolloverType: DEFAULT_ROLLOVER_TYPE, + outputFormat: DEFAULT_OUTPUT_FORMAT, + MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, + MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + 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 +366,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..5044a3e74e7 100644 --- a/ecs-agent/logger/log.go +++ b/ecs-agent/logger/log.go @@ -44,18 +44,34 @@ const ( DEFAULT_TIMESTAMP_FORMAT = time.RFC3339 DEFAULT_MAX_FILE_SIZE float64 = 10 DEFAULT_MAX_ROLL_COUNT int = 24 + DEFAULT_LOGTO_STDOUT = true ) +// Because timestamp format will be called in the custom formatter +// for each log message processed, it should not be handled +// with an explicitly write protected configuration. +var timestampFormat = DEFAULT_TIMESTAMP_FORMAT + +// 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 - MaxFileSizeMB float64 - logfile string - driverLevel string - instanceLevel string - outputFormat string - timestampFormat string - lock sync.Mutex + RolloverType string + MaxRollCount int + MaxFileSizeMB float64 + logfile string + driverLevel string + instanceLevel string + outputFormat string + logToStdout bool + lock sync.Mutex } var Config *logConfig @@ -89,7 +105,7 @@ func logfmtFormatter(params string) seelog.FormatterFunc { buf.WriteString(level.String()) buf.WriteByte(' ') buf.WriteString("time=") - buf.WriteString(context.CallTime().UTC().Format(Config.timestampFormat)) + buf.WriteString(context.CallTime().UTC().Format(timestampFormat)) buf.WriteByte(' ') // temporary measure to make this change backwards compatible as we update to structured logs if strings.HasPrefix(message, structuredTxtFormatPrefix) { @@ -114,7 +130,7 @@ func jsonFormatter(params string) seelog.FormatterFunc { buf.WriteString(`{"level":"`) buf.WriteString(level.String()) buf.WriteString(`","time":"`) - buf.WriteString(context.CallTime().UTC().Format(Config.timestampFormat)) + buf.WriteString(context.CallTime().UTC().Format(timestampFormat)) buf.WriteString(`",`) // temporary measure to make this change backwards compatible as we update to structured logs if strings.HasPrefix(message, structuredJsonFormatPrefix) { @@ -144,14 +160,26 @@ func reloadConfig() { } func seelogConfig() string { + driverLogChildren := []string{} + platformLogConfig := platformLogConfig() + if Config.logToStdout { + driverLogChildren = append(driverLogChildren, ` `) + } + if platformLogConfig != "" { + driverLogChildren = append(driverLogChildren, platformLogConfig) + } + c := ` - + ` + if len(driverLogChildren) > 0 { + c += ` - ` - c += platformLogConfig() - c += ` + ` + c += strings.Join(driverLogChildren, "\n") + c += ` ` + } if Config.logfile != "" { c += ` ` @@ -159,6 +187,9 @@ func seelogConfig() string { c += ` ` + } else if Config.RolloverType == "none" { + c += ` + ` } else { c += ` 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() + } else { + seelog.Error("Invalid Max File Size Provided") + } +} + +// 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" || rolloverType == "none" { + Config.lock.Lock() + defer Config.lock.Unlock() + + Config.RolloverType = rolloverType + reloadConfig() + } else { + seelog.Error("Invalid log rollover type provided") + } } // SetTimestampFormat sets the time formatting @@ -271,27 +323,38 @@ func SetConfigMaxFileSizeMB(maxSizeInMB float64) { // a valid time format such as time.RFC3339 // or "2006-01-02T15:04:05.000". func SetTimestampFormat(format string) { + if format != "" { + timestampFormat = format + } +} + +// 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() - if format != "" { - Config.timestampFormat = format - } + Config.logToStdout = duplicate + reloadConfig() } func init() { Config = &logConfig{ - logfile: os.Getenv(LOGFILE_ENV_VAR), - driverLevel: DEFAULT_LOGLEVEL, - instanceLevel: setInstanceLevelDefault(), - RolloverType: DEFAULT_ROLLOVER_TYPE, - outputFormat: DEFAULT_OUTPUT_FORMAT, - MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, - MaxRollCount: DEFAULT_MAX_ROLL_COUNT, - timestampFormat: DEFAULT_TIMESTAMP_FORMAT, + logfile: os.Getenv(LOGFILE_ENV_VAR), + driverLevel: DEFAULT_LOGLEVEL, + instanceLevel: setInstanceLevelDefault(), + RolloverType: DEFAULT_ROLLOVER_TYPE, + outputFormat: DEFAULT_OUTPUT_FORMAT, + MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, + MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + 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 +366,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..e8b098d231d 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) @@ -241,8 +241,11 @@ 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..c670997e5c2 100644 --- a/ecs-agent/logger/log_unix_test.go +++ b/ecs-agent/logger/log_unix_test.go @@ -23,16 +23,23 @@ import ( "github.com/stretchr/testify/require" ) -func TestSeelogConfig_Default(t *testing.T) { +const DEFAULT_TEST_LOG_FILE = "foo.log" + +func SetDefaultConfig() { Config = &logConfig{ - logfile: "foo.log", + logfile: DEFAULT_TEST_LOG_FILE, driverLevel: DEFAULT_LOGLEVEL, - instanceLevel: DEFAULT_LOGLEVEL, + instanceLevel: setInstanceLevelDefault(), RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, + logToStdout: DEFAULT_LOGTO_STDOUT, } +} + +func TestSeelogConfig_Default(t *testing.T) { + SetDefaultConfig() c := seelogConfig() require.Equal(t, ` @@ -61,6 +68,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,16 +86,37 @@ func TestSeelogConfig_WithoutLogFile(t *testing.T) { `, c) } -func TestSeelogConfig_DebugLevel(t *testing.T) { +func TestSeeLogConfig_WithoutStdout(t *testing.T) { Config = &logConfig{ logfile: "foo.log", - driverLevel: "debug", + driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, - RolloverType: DEFAULT_ROLLOVER_TYPE, + 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) { + SetDefaultConfig() + SetDriverLogLevel("debug") + c := seelogConfig() require.Equal(t, ` @@ -117,6 +146,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, ` @@ -147,6 +177,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, ` @@ -177,6 +208,7 @@ func TestSeelogConfig_SizeRolloverRollCountChange(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: 10, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -207,6 +239,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,6 +261,64 @@ func TestSeelogConfig_JSONOutput(t *testing.T) { `, c) } +func TestSeelogConfig_JSONNoStdout(t *testing.T) { + 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 = &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 = &logConfig{ logfile: "foo.log", @@ -237,6 +328,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,15 +351,13 @@ func TestSeelogConfig_NoOnInstanceLog(t *testing.T) { } func TestSeelogConfig_DifferentLevels(t *testing.T) { - Config = &logConfig{ - logfile: "foo.log", - driverLevel: "warn", - instanceLevel: "critical", - RolloverType: DEFAULT_ROLLOVER_TYPE, - outputFormat: DEFAULT_OUTPUT_FORMAT, - MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, - MaxRollCount: DEFAULT_MAX_ROLL_COUNT, - } + SetDefaultConfig() + + SetDriverLogLevel("warn") + SetInstanceLogLevel("critical") + defer SetDriverLogLevel(DEFAULT_LOGLEVEL) + defer SetInstanceLogLevel(setInstanceLevelDefault()) + c := seelogConfig() require.Equal(t, ` @@ -275,7 +365,7 @@ func TestSeelogConfig_DifferentLevels(t *testing.T) { - + @@ -300,6 +390,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, ` @@ -320,3 +411,126 @@ func TestSeelogConfig_FileLevelDefault(t *testing.T) { `, c) } + +func TestSetLogFile(t *testing.T) { + SetDefaultConfig() + SetRolloverType("none") + SetConfigLogFile("bar.log") + defer SetConfigLogFile("foo.log") + + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + + + + +`, c) +} + +func TestSetOutputFormat(t *testing.T) { + SetDefaultConfig() + SetConfigOutputFormat("json") + defer SetConfigOutputFormat(DEFAULT_OUTPUT_FORMAT) + + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + + + + +`, c) +} + +func TestSetMaxFileSizeMB(t *testing.T) { + SetDefaultConfig() + SetRolloverType("size") + SetConfigMaxFileSizeMB(5) + defer SetRolloverType(DEFAULT_ROLLOVER_TYPE) + defer SetConfigMaxFileSizeMB(DEFAULT_MAX_FILE_SIZE) + + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + + + + +`, c) +} + +func TestSetRolloverType(t *testing.T) { + SetDefaultConfig() + SetRolloverType("none") + defer SetRolloverType(DEFAULT_ROLLOVER_TYPE) + + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + + + + +`, c) +} + +func TestSetLogToStdout(t *testing.T) { + SetDefaultConfig() + SetLogToStdout(false) + defer SetLogToStdout(DEFAULT_LOGTO_STDOUT) + + c := seelogConfig() + require.Equal(t, ` + + + + + + + + + + + +`, c) +} diff --git a/ecs-agent/logger/log_windows_test.go b/ecs-agent/logger/log_windows_test.go index c763d595ac8..83fd73482b5 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, ` @@ -39,6 +40,7 @@ func TestSeelogConfigWindows_Default(t *testing.T) { + @@ -62,6 +64,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, ` @@ -69,6 +72,7 @@ func TestSeelogConfigWindows_WithoutLogFile(t *testing.T) { + @@ -89,6 +93,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, ` @@ -96,6 +101,7 @@ func TestSeelogConfigWindows_DebugLevel(t *testing.T) { + @@ -120,6 +126,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, ` @@ -127,6 +134,7 @@ func TestSeelogConfigWindows_SizeRollover(t *testing.T) { + @@ -151,6 +159,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, ` @@ -158,6 +167,7 @@ func TestSeelogConfigWindows_SizeRolloverFileSizeChange(t *testing.T) { + @@ -182,6 +192,7 @@ func TestSeelogConfigWindows_SizeRolloverRollCountChange(t *testing.T) { outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: 10, + logToStdout: DEFAULT_LOGTO_STDOUT, } c := seelogConfig() require.Equal(t, ` @@ -189,6 +200,7 @@ func TestSeelogConfigWindows_SizeRolloverRollCountChange(t *testing.T) { + @@ -213,6 +225,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, ` @@ -220,6 +233,7 @@ func TestSeelogConfigWindows_JSONOutput(t *testing.T) { + @@ -244,6 +258,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, ` @@ -251,6 +266,7 @@ func TestSeelogConfigWindows_NoOnInstanceLog(t *testing.T) { + @@ -275,6 +291,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, ` @@ -282,6 +299,7 @@ func TestSeelogConfigWindows_DifferentLevels(t *testing.T) { + @@ -309,6 +327,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, ` @@ -316,6 +335,7 @@ func TestSeelogConfigWindows_FileLevelDefault(t *testing.T) { +