1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00
juanfont.headscale/cmd/headscale/headscale.go

66 lines
1.4 KiB
Go
Raw Normal View History

2020-06-21 12:33:43 +02:00
package main
import (
2021-08-05 20:19:25 +02:00
"os"
"time"
2020-06-21 12:33:43 +02:00
"github.com/efekarakus/termcolor"
"github.com/juanfont/headscale/cmd/headscale/cli"
2021-08-05 20:19:25 +02:00
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
2020-06-21 12:33:43 +02:00
)
2021-04-25 17:24:42 +02:00
func main() {
var colors bool
switch l := termcolor.SupportLevel(os.Stderr); l {
case termcolor.Level16M:
colors = true
case termcolor.Level256:
colors = true
case termcolor.LevelBasic:
colors = true
default:
// no color, return text as is.
log.Trace().Msg("Colors are not supported, disabling")
colors = false
}
// Adhere to no-color.org manifesto of allowing users to
// turn off color in cli/services
if _, noColorIsSet := os.LookupEnv("NO_COLOR"); noColorIsSet {
log.Trace().Msg("NO_COLOR is set, disabling colors")
colors = false
}
2021-08-05 20:19:25 +02:00
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
NoColor: !colors,
2021-08-05 20:19:25 +02:00
})
2021-06-05 11:13:28 +02:00
err := cli.LoadConfig("")
if err != nil {
2021-08-05 20:19:25 +02:00
log.Fatal().Err(err)
}
logLevel := viper.GetString("log_level")
switch logLevel {
case "trace":
zerolog.SetGlobalLevel(zerolog.TraceLevel)
case "debug":
zerolog.SetGlobalLevel(zerolog.DebugLevel)
case "info":
zerolog.SetGlobalLevel(zerolog.InfoLevel)
case "warn":
zerolog.SetGlobalLevel(zerolog.WarnLevel)
case "error":
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
default:
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
2021-07-25 15:14:09 +02:00
cli.Execute()
}