func config() *aws.Config { log := aws.LogLevel(aws.LogOff) cfg := app.NewConfig() if cfg.AwsLog { log = aws.LogLevel(aws.LogDebug) } return &aws.Config{ Credentials: credentials.NewChainCredentials( []credentials.Provider{ &credentials.EnvProvider{}, &ec2rolecreds.EC2RoleProvider{ExpiryWindow: cfg.AwsRoleExpiry * time.Minute}, }), Region: aws.String(os.Getenv("AWS_REGION")), LogLevel: log, } }
func init() { level = logLevel(math.Min(float64(trace), math.Max(float64(fatal), float64(config.NewConfig().LogLevel)))) handle := ioutil.Discard if level >= fatal { handle = os.Stderr } Fatal = log.New(handle, "FATAL: ", log.Ldate|log.Ltime|log.Lshortfile) handle = ioutil.Discard if level >= err { handle = os.Stderr } Error = log.New(handle, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) handle = ioutil.Discard if level >= warn { handle = os.Stdout } Warn = log.New(handle, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile) handle = ioutil.Discard if level >= info { handle = os.Stdout } Info = log.New(handle, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) handle = ioutil.Discard if level >= debug { handle = os.Stdout } Debug = log.New(handle, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile) handle = ioutil.Discard if level >= trace { handle = os.Stdout } Trace = log.New(handle, "TRACE: ", log.Ldate|log.Ltime|log.Lshortfile) }
func main() { cfg := config.NewConfig() logs.Debug.Print("[config] " + cfg.String()) logs.Info.Printf("[service] listening on port %v", cfg.Port) logs.Fatal.Print(http.ListenAndServe(":"+fmt.Sprint(cfg.Port), nil)) }
func init() { cfg = config.NewConfig() }