-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
36 lines (29 loc) · 968 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"os"
"github.com/aws/aws-lambda-go/lambda"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/sudores/script-firefly-iii-budget-resp/cnf"
fireflyiii "github.com/sudores/script-firefly-iii-budget-resp/firefly-iii"
)
func main() {
cfg, err := cnf.Parse()
if err != nil {
log.Fatal().Err(err).Msg("Failed to parse config")
}
loggingInit(cfg.LogLevel)
log.Info().Msg("Logging setup success")
ffi := fireflyiii.NewFireflyiiiConnection(cfg.FFIToken, cfg.FFIURL, cfg.BudgetPathRelation)
lambda.Start(ffi)
}
// loggingInit setups the logging of whole app
func loggingInit(logLevel string) {
log.Logger = zerolog.New(os.Stdout).With().Timestamp().Logger()
level, err := zerolog.ParseLevel(logLevel)
if err != nil {
log.Fatal().Msgf(`Log level "%s" is unrecognized. Eligible log levels are: trace, debug, info, err, fatal, panic`, logLevel)
}
zerolog.SetGlobalLevel(level)
log.Debug().Msg("Logger initialized")
}