moving logging function to common setting up client logging and db

This commit is contained in:
2020-06-15 15:49:53 -04:00
parent 88333417d4
commit 55561d8667
6 changed files with 54 additions and 25 deletions

View File

@@ -10,7 +10,10 @@ import (
clientcmd "github.com/deranjer/gvc/client/clientcmd"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
config "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common"
"github.com/deranjer/gvc/common/database"
"github.com/deranjer/store"
"github.com/rs/zerolog"
)
var version = "0.1.5"
@@ -31,7 +34,7 @@ func main() {
// Setting up a blank config to read the .toml file in if one exists
var conf clientconfig.Gvcconfig
isRepo := validateRepo()
if isRepo {
if isRepo { // If repo folder exists, treat it like a repo and setup logging and database. If not a repo will not need any of this
err := store.Load(configPath, &conf)
if err != nil {
fmt.Printf("Error loading config file into struct, please fix config, panic! \n%s", err)
@@ -42,7 +45,24 @@ func main() {
fmt.Println("Error validating config, your config file is corrupt! ", err)
os.Exit(0)
}
fmt.Println("Attempting to start logger...")
// Setting up the logger to file output
logFile, err := os.OpenFile(".gvc/gvclog.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("unable to open log file at: %s, exiting with error: %s", ".gvc/gvclog.log", err)
}
defer logFile.Close()
// Setup non-http logging (using middleware for Echo http logging)
logLevel, err := common.SetLogLevel(conf.LogLevel)
if err != nil {
fmt.Println("invalid log level set in config, setting to info")
}
clientlog := zerolog.New(logFile)
clientlog.WithLevel(logLevel)
// Check/Setup the database with logging
database.NewDB(".gvc/gvc.db", &clientlog)
}
// Initialize our new cli
cli := clir.NewCli("gvcc", "Version control client for GVC", version)