2019-10-03 19:30:04 +00:00
|
|
|
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
|
|
|
package main
|
|
|
|
|
2019-10-25 15:09:31 +00:00
|
|
|
import "os"
|
|
|
|
import "time"
|
2019-10-25 12:01:38 +00:00
|
|
|
import "github.com/rs/zerolog"
|
|
|
|
import "github.com/rs/zerolog/log"
|
2019-10-25 15:09:31 +00:00
|
|
|
import "golang.org/x/crypto/ssh/terminal"
|
2019-10-03 19:30:04 +00:00
|
|
|
|
|
|
|
var Version string
|
|
|
|
var Buildtime string
|
|
|
|
var Builduser string
|
|
|
|
var Buildarch string
|
2019-10-25 16:17:14 +00:00
|
|
|
var Appname string
|
2019-10-03 19:30:04 +00:00
|
|
|
|
|
|
|
func main() {
|
2019-10-25 15:09:31 +00:00
|
|
|
initLogging()
|
2019-10-25 12:01:38 +00:00
|
|
|
identify()
|
2019-10-03 19:30:04 +00:00
|
|
|
serve()
|
|
|
|
}
|
|
|
|
|
2019-10-25 12:01:38 +00:00
|
|
|
func identify() {
|
|
|
|
log.Info().
|
|
|
|
Str("app", Appname).
|
|
|
|
Str("version", Version).
|
|
|
|
Str("buildarch", Buildarch).
|
|
|
|
Str("buildtime", Buildtime).
|
|
|
|
Str("builduser", Builduser).
|
|
|
|
Msg("starting")
|
2019-10-03 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 15:09:31 +00:00
|
|
|
func initLogging() {
|
2019-10-25 16:17:14 +00:00
|
|
|
|
|
|
|
// always log in UTC
|
|
|
|
zerolog.TimestampFunc = func() time.Time {
|
|
|
|
return time.Now().UTC()
|
|
|
|
}
|
|
|
|
|
2019-10-25 15:09:31 +00:00
|
|
|
log.Logger = log.With().Caller().Stack().Logger()
|
|
|
|
|
2019-10-25 12:01:38 +00:00
|
|
|
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
2019-10-25 16:17:14 +00:00
|
|
|
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339Nano}
|
2019-10-25 15:09:31 +00:00
|
|
|
log.Logger = zerolog.New(output).With().Caller().Stack().Logger().With().Timestamp().Logger()
|
2019-10-25 12:01:38 +00:00
|
|
|
}
|
2019-10-03 19:30:04 +00:00
|
|
|
|
2019-10-25 12:01:38 +00:00
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
2019-10-25 15:09:31 +00:00
|
|
|
if os.Getenv("DEBUG") != "" {
|
2019-10-25 12:01:38 +00:00
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
}
|
2019-10-03 19:30:04 +00:00
|
|
|
}
|