adding logging to server

This commit is contained in:
2020-06-15 15:24:56 -04:00
parent d335549fd5
commit 88333417d4
10 changed files with 72 additions and 37 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/deranjer/store"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/rs/zerolog"
)
var version = "0.1"
@@ -26,6 +27,7 @@ func main() {
fmt.Println("Since no config found, creating a default config to use...")
conf = serverconfig.GvcServerConfig{
LogFile: "gvclog.log",
LogLevel: 2,
Version: "0.1",
Port: 80,
RepoRootPath: "repos", //default repos directory will be cwd\repos
@@ -55,8 +57,15 @@ func main() {
log.Fatalf("unable to open log file at: %s, exiting with error: %s", conf.LogFile, err)
}
defer logFile.Close()
// Setup non-http logging (using middleware for Echo http logging)
logLevel, err := serverconfig.SetLogLevel(conf.LogLevel)
if err != nil {
fmt.Println("invalid log level set in config, setting to info")
}
serverlog := zerolog.New(logFile)
serverlog.WithLevel(logLevel)
// Check/Setup the database
database.NewDB(conf.DatabaseLocation)
database.NewDB(conf.DatabaseLocation, &serverlog)
// Setup the web server
e := echo.New()
// Setup the logger to print to the file specified in config