mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-28 12:46:09 +01:00
Add more log to locate issue
This commit is contained in:
parent
7aa0a97d10
commit
c3953a62fd
42
serve.go
42
serve.go
|
@ -49,7 +49,7 @@ func init() {
|
|||
level := "0"
|
||||
os.MkdirAll("log", os.ModePerm)
|
||||
log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log"))
|
||||
log.Info("start logging...")
|
||||
log.Trace("start logging...")
|
||||
}
|
||||
|
||||
func parseCmd(cmd string) (string, string) {
|
||||
|
@ -80,17 +80,20 @@ func runServ(k *cli.Context) {
|
|||
keys := strings.Split(os.Args[2], "-")
|
||||
if len(keys) != 2 {
|
||||
fmt.Println("auth file format error")
|
||||
log.Error("auth file format error")
|
||||
return
|
||||
}
|
||||
|
||||
keyId, err := strconv.ParseInt(keys[1], 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println("auth file format error")
|
||||
log.Error("auth file format error")
|
||||
return
|
||||
}
|
||||
user, err := models.GetUserByKeyId(keyId)
|
||||
if err != nil {
|
||||
fmt.Println("You have no right to access")
|
||||
log.Error("You have no right to access")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -105,6 +108,7 @@ func runServ(k *cli.Context) {
|
|||
rr := strings.SplitN(rRepo, "/", 2)
|
||||
if len(rr) != 2 {
|
||||
println("Unavilable repository", args)
|
||||
log.Error("Unavilable repository %v", args)
|
||||
return
|
||||
}
|
||||
repoName := rr[1]
|
||||
|
@ -122,11 +126,12 @@ func runServ(k *cli.Context) {
|
|||
isExist = false
|
||||
if isRead {
|
||||
println("Repository", user.Name+"/"+repoName, "is not exist")
|
||||
log.Error("Repository " + user.Name + "/" + repoName + " is not exist")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
println("Get repository error:", err)
|
||||
log.Error(err.Error())
|
||||
log.Error("Get repository error: " + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +147,7 @@ func runServ(k *cli.Context) {
|
|||
}
|
||||
if !has {
|
||||
println("You have no right to write this repository")
|
||||
log.Error("You have no right to access this repository")
|
||||
return
|
||||
}
|
||||
case isRead:
|
||||
|
@ -161,10 +167,12 @@ func runServ(k *cli.Context) {
|
|||
}
|
||||
if !has {
|
||||
println("You have no right to access this repository")
|
||||
log.Error("You have no right to access this repository")
|
||||
return
|
||||
}
|
||||
default:
|
||||
println("Unknown command")
|
||||
log.Error("Unknown command")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -175,23 +183,23 @@ func runServ(k *cli.Context) {
|
|||
_, err = models.CreateRepository(user, repoName, "", "", "", false, true)
|
||||
if err != nil {
|
||||
println("Create repository failed")
|
||||
log.Error(err.Error())
|
||||
log.Error("Create repository failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rep, err = git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
println("OpenRepository failed:", err.Error())
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
rep, err = git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
println("OpenRepository failed:", err.Error())
|
||||
log.Error("OpenRepository failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
refs, err := rep.AllReferencesMap()
|
||||
if err != nil {
|
||||
println("Get All References failed:", err.Error())
|
||||
log.Error(err.Error())
|
||||
log.Error("Get All References failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -208,7 +216,7 @@ func runServ(k *cli.Context) {
|
|||
|
||||
if err = gitcmd.Run(); err != nil {
|
||||
println("execute command error:", err.Error())
|
||||
log.Error(err.Error())
|
||||
log.Error("execute command error: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -236,6 +244,7 @@ func runServ(k *cli.Context) {
|
|||
}
|
||||
if refname == "" {
|
||||
println("No find any reference name:", b.String())
|
||||
log.Error("No find any reference name: " + b.String())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -248,17 +257,18 @@ func runServ(k *cli.Context) {
|
|||
refs, err = rep.AllReferencesMap()
|
||||
if err != nil {
|
||||
println("Get All References failed:", err.Error())
|
||||
log.Error(err.Error())
|
||||
log.Error("Get All References failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
if ref, ok = refs[refname]; !ok {
|
||||
log.Error("unknow reference name -", refname, "-", b.String())
|
||||
log.Error("unknow reference name -", refname, "-", b.String())
|
||||
return
|
||||
}
|
||||
l, err = ref.AllCommits()
|
||||
if err != nil {
|
||||
println("Get All Commits failed:", err.Error())
|
||||
log.Error(err.Error())
|
||||
log.Error("Get All Commits failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
@ -268,14 +278,14 @@ func runServ(k *cli.Context) {
|
|||
last, err = ref.LastCommit()
|
||||
if err != nil {
|
||||
println("Get last commit failed:", err.Error())
|
||||
log.Error(err.Error())
|
||||
log.Error("Get last commit failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ref2, err := rep.LookupReference(ref.Name)
|
||||
if err != nil {
|
||||
println("look up reference failed:", err.Error())
|
||||
log.Error(err.Error())
|
||||
log.Error("look up reference failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -283,7 +293,7 @@ func runServ(k *cli.Context) {
|
|||
before, err := ref2.LastCommit()
|
||||
if err != nil {
|
||||
println("Get last commit failed:", err.Error())
|
||||
log.Error(err.Error())
|
||||
log.Error("Get last commit failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
//log.Info("----", before.Id(), "-----", last.Id())
|
||||
|
|
Loading…
Reference in a new issue