github.com/apex/up@v1.7.1/internal/logs/logs.go (about) 1 // Package logs provides logging utilities. 2 package logs 3 4 import ( 5 "os" 6 7 "github.com/apex/log" 8 ) 9 10 // Fields returns the global log fields. 11 func Fields() log.Fields { 12 f := log.Fields{ 13 "app": os.Getenv("AWS_LAMBDA_FUNCTION_NAME"), 14 "region": os.Getenv("AWS_REGION"), 15 "version": os.Getenv("AWS_LAMBDA_FUNCTION_VERSION"), 16 "stage": os.Getenv("UP_STAGE"), 17 } 18 19 if s := os.Getenv("UP_COMMIT"); s != "" { 20 f["commit"] = s 21 } 22 23 return f 24 } 25 26 // Plugin returns a log context for the given plugin name. 27 func Plugin(name string) log.Interface { 28 f := Fields() 29 f["plugin"] = name 30 return log.WithFields(f) 31 }