added server logging to file, added logging and formatting to info and lock commands

This commit is contained in:
2020-06-09 23:22:07 -04:00
parent 441a9ed233
commit 161843f4c8
15 changed files with 126 additions and 66 deletions

View File

@@ -1,3 +1,4 @@
logfile = "gvclog.log"
version = "0.1"
port = 80
ip = ""
@@ -15,7 +16,7 @@ reporootpath = "F:\\repos"
key = "12345"
lastcommit = "4343434343434"
[repo.locked]
files = ["client1.exe", "client2.exe"]
files = ["client1.exe", "client2.exe", "client.go"]
[repo.defaultignore]
[repo.nocompress]

View File

@@ -1,6 +0,0 @@
version = "0.1"
port = 80
ip = ""
rawport = 0
reporootpath = "F:\\repos"

View File

@@ -2,7 +2,6 @@ package engine
import (
"fmt"
"log"
"net/http"
"github.com/deranjer/gvc/common"
@@ -28,6 +27,10 @@ func (Server *GVCServer) GetInfo(context echo.Context) error {
}
}
}
if repoInfo.Repo.RepoName == "" {
return echo.NewHTTPError(http.StatusNotFound, "repo apparently not found")
}
Server.Echo.Logger.Infof("returning information about repo: %s", repo)
return context.JSONPretty(http.StatusAccepted, repoInfo, " ")
}
@@ -36,16 +39,18 @@ func (Server *GVCServer) LockFile(context echo.Context) error {
fileType := context.Param("type")
fileName := context.Param("name")
repoName := context.Param("repo")
fmt.Printf("Lockfile: %s %s %s", repoName, fileType, fileName)
Server.Echo.Logger.Infof("Lockfile: %s %s %s", repoName, fileType, fileName)
var locked common.FileTypes
var index int
for i, repo := range Server.Config.Repos {
if repo.RepoName == repoName {
index = i
locked = Server.Config.Repos[i].Locked
}
}
err := common.CheckFileTypes(fileName, fileType, locked) // making sure fi/f/wc is not already locked or cannot be locked.
if err != nil {
return fmt.Errorf("failed checking file lock: %s", err)
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed checking file lock: %s", err))
}
switch fileType {
case "file":
@@ -58,12 +63,13 @@ func (Server *GVCServer) LockFile(context echo.Context) error {
fmt.Println("Wildcard: ", fileName)
locked.Exts = append(locked.Exts, fileName)
}
fmt.Println("Locked: ", locked) // TODO!!!!!!!!!!!! Write this to conf
Server.Config.Repos[index].Locked = locked
Server.Echo.Logger.Infof("server attempting to lock file: %s of type %s", fileName, fileType)
err = store.Save(serverconfig.DefaultConfigPath, Server.Config) // Save our new default config back to TOML so it can be read in
if err != nil {
log.Fatalf("unable to save config to toml file: %s", err)
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("server unable to save lock to server: %s", err))
}
return nil
return context.String(http.StatusAccepted, "file locked on server")
}
// Refresh sends all updated information to client (like git fetch)

14
server/gvclog.log Normal file
View File

@@ -0,0 +1,14 @@
{"time":"2020-06-09T20:56:46.5428576-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/lock/gvc/file/client.go","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":500,"error":"code=500, message=failed checking file lock: file name is on excludeList, cannot add file with name client.go","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":106}
{"time":"2020-06-09T21:13:05.528876-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/lock/gvc/file/client.go","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":500,"error":"code=500, message=failed checking file lock: file name is on excludeList, cannot add file with name client.go","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":106}
{"time":"2020-06-09T22:09:36.2468239-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/lock/gvc/file/client.go","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":500,"error":"code=500, message=failed checking file lock: file name is on excludeList, cannot add file with name client.go","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":106}
{"time":"2020-06-09T22:33:08.8260147-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/info/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":202,"error":"","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":588}
{"time":"2020-06-09T22:33:49.1917423-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/info/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":404,"error":"code=404, message=repo apparently not found","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":40}
{"time":"2020-06-09T22:35:01.8253061-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/info/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":404,"error":"code=404, message=repo apparently not found","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":40}
{"time":"2020-06-09T22:35:34.7362521-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/info/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":202,"error":"","latency":1000500,"latency_human":"1.0005ms","bytes_in":0,"bytes_out":414}
{"time":"2020-06-09T22:35:59.5823542-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/info/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":404,"error":"code=404, message=repo apparently not found","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":40}
{"time":"2020-06-09T22:52:11.3303094-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/refreshgvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":404,"error":"code=404, message=Not Found","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":24}
{"time":"2020-06-09T22:53:26.1999036-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/refreshgvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":404,"error":"code=404, message=Not Found","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":24}
{"time":"2020-06-09T22:54:20.1925112-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/refresh/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":200,"error":"","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":177}
{"time":"2020-06-09T22:54:58.6865514-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/refresh/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":200,"error":"","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":177}
{"time":"2020-06-09T22:56:01.309063-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/refresh/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":200,"error":"","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":177}
{"time":"2020-06-09T22:56:25.9765046-04:00","id":"","remote_ip":"::1","host":"localhost:80","method":"GET","uri":"/refresh/gvc","user_agent":"go-resty/2.3.0 (https://github.com/go-resty/resty)","status":200,"error":"","latency":0,"latency_human":"0s","bytes_in":0,"bytes_out":177}

View File

@@ -2,12 +2,14 @@ package main
import (
"fmt"
"log"
"os"
"github.com/deranjer/gvc/server/engine"
serverconfig "github.com/deranjer/gvc/server/serverconfig"
"github.com/deranjer/store"
"github.com/labstack/echo"
"github.com/labstack/gommon/log"
"github.com/labstack/echo/middleware"
)
var version = "0.1"
@@ -22,6 +24,7 @@ func main() {
fmt.Printf("Unable to find config file: %s\n", err)
fmt.Println("Since no config found, creating a default config to use...")
conf = serverconfig.GvcServerConfig{
LogFile: "gvclog.log",
Version: "0.1",
Port: 80,
RepoRootPath: "repos", //default repos directory will be cwd\repos
@@ -43,9 +46,20 @@ func main() {
// Setup a new server instance
var server engine.GVCServer
server.Config = conf
log.Info("Logger starting...")
fmt.Println("Attempting to start logger...")
// Setting up the logger to file output
logFile, err := os.OpenFile(conf.LogFile, 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", conf.LogFile, err)
}
defer logFile.Close()
// Setup the web server
e := echo.New()
// Setup the logger to print to the file specified in config
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Output: logFile,
}))
e.Logger.Info("echo logger has started")
server.Echo = e
//Start the routes
//e.GET("/hello", server.Hello)

View File

@@ -1,30 +0,0 @@
version = "0.1"
port = 80
ip = ""
rawport = 0
reporootpath = "F:\\repos"
[[repo]]
rootpath = ""
reponame = "gvc"
defaultbranch = "master"
localbranches = ["master"]
[[repo.client]]
name = "deranjer"
key = "12345"
lastcommit = "4343434343434"
[repo.locked]
files = ["client1.exe", "client2.exe"]
[repo.defaultignore]
[repo.nocompress]
[[repo]]
rootpath = ""
reponame = "testrepo"
defaultbranch = "master"
localbranches = ["master", "feature1"]
[repo.locked]
[repo.defaultignore]
[repo.nocompress]

View File

@@ -40,6 +40,10 @@ func ValidateConfig(conf *GvcServerConfig, configPath string, version string) er
fmt.Printf("No version found, inputing current server version: %s\n", version)
conf.Version = version
}
if conf.LogFile == "" { // If no log file specified, set log location
fmt.Printf("No logfile found in config, setting it to: gvclog.log :in root dir:")
conf.LogFile = "gvclog.log"
}
if conf.RepoRootPath == "" {
fmt.Println("Repo root path: ", conf.RepoRootPath)
path, err := os.Getwd()

View File

@@ -4,6 +4,7 @@ import "github.com/deranjer/gvc/common"
// GvcServerConfig will hold the base server settings
type GvcServerConfig struct {
LogFile string `toml:"logfile"` // Where to store the echo logs
Version string `toml:"version"` // The server version
Port int `toml:"port"` // The port that the server will listed on
BindIP string `toml:"ip"` // What IP to bind the server to. If empty will bind to all interfaces