2019-11-06 12:33:46 +00:00
|
|
|
package main
|
|
|
|
|
2020-11-09 13:43:23 +00:00
|
|
|
import (
|
2021-05-25 10:23:29 +00:00
|
|
|
"context"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2021-05-28 08:57:28 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/pkg/logger"
|
2020-11-09 13:43:23 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-03-30 22:46:33 +00:00
|
|
|
func main() {
|
|
|
|
var (
|
|
|
|
v = settings()
|
|
|
|
l = newLogger(v)
|
|
|
|
)
|
2021-05-25 10:23:29 +00:00
|
|
|
globalContext, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
2021-03-30 22:46:33 +00:00
|
|
|
app := newApp(globalContext, WithLogger(l), WithConfig(v))
|
|
|
|
go app.Serve(globalContext)
|
|
|
|
app.Wait()
|
|
|
|
}
|
|
|
|
|
2020-11-09 13:43:23 +00:00
|
|
|
func newLogger(v *viper.Viper) *zap.Logger {
|
|
|
|
options := []logger.Option{
|
2020-11-27 15:18:53 +00:00
|
|
|
logger.WithLevel(v.GetString(cfgLoggerLevel)),
|
|
|
|
logger.WithTraceLevel(v.GetString(cfgLoggerTraceLevel)),
|
|
|
|
logger.WithFormat(v.GetString(cfgLoggerFormat)),
|
|
|
|
logger.WithSamplingInitial(v.GetInt(cfgLoggerSamplingInitial)),
|
|
|
|
logger.WithSamplingThereafter(v.GetInt(cfgLoggerSamplingThereafter)),
|
|
|
|
logger.WithAppName(v.GetString(cfgApplicationName)),
|
|
|
|
logger.WithAppVersion(v.GetString(cfgApplicationVersion)),
|
2020-11-09 13:43:23 +00:00
|
|
|
}
|
2020-11-27 15:18:53 +00:00
|
|
|
if v.GetBool(cfgLoggerNoCaller) {
|
2020-11-09 13:43:23 +00:00
|
|
|
options = append(options, logger.WithoutCaller())
|
|
|
|
}
|
2020-11-27 15:18:53 +00:00
|
|
|
if v.GetBool(cfgLoggerNoDisclaimer) {
|
2020-11-09 13:43:23 +00:00
|
|
|
options = append(options, logger.WithoutDisclaimer())
|
|
|
|
}
|
|
|
|
l, err := logger.New(options...)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|