Fix bug related to log
This commit is contained in:
parent
d3a987eded
commit
2846ff7d31
@ -12,6 +12,8 @@ github.com/nfnt/resize =
|
||||
github.com/lunny/xorm =
|
||||
github.com/go-sql-driver/mysql =
|
||||
github.com/lib/pq =
|
||||
github.com/qiniu/log =
|
||||
code.google.com/p/goauth2 =
|
||||
github.com/gogits/logs =
|
||||
github.com/gogits/binding =
|
||||
github.com/gogits/git =
|
||||
@ -19,7 +21,6 @@ github.com/gogits/gfm =
|
||||
github.com/gogits/cache =
|
||||
github.com/gogits/session =
|
||||
github.com/gogits/webdav =
|
||||
code.google.com/p/goauth2 =
|
||||
|
||||
[res]
|
||||
include = templates|public|conf
|
||||
|
2
bee.json
2
bee.json
@ -13,6 +13,8 @@
|
||||
"others": [
|
||||
"modules",
|
||||
"$GOPATH/src/github.com/gogits/binding",
|
||||
"$GOPATH/src/github.com/gogits/webdav",
|
||||
"$GOPATH/src/github.com/gogits/logs",
|
||||
"$GOPATH/src/github.com/gogits/git",
|
||||
"$GOPATH/src/github.com/gogits/gfm"
|
||||
]
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/Unknwon/goconfig"
|
||||
qlog "github.com/qiniu/log"
|
||||
|
||||
"github.com/gogits/cache"
|
||||
"github.com/gogits/session"
|
||||
@ -105,16 +106,14 @@ func newLogService() {
|
||||
LogMode = Cfg.MustValue("log", "MODE", "console")
|
||||
modeSec := "log." + LogMode
|
||||
if _, err := Cfg.GetSection(modeSec); err != nil {
|
||||
fmt.Printf("Unknown log mode: %s\n", LogMode)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Unknown log mode: %s\n", LogMode)
|
||||
}
|
||||
|
||||
// Log level.
|
||||
levelName := Cfg.MustValue("log."+LogMode, "LEVEL", "Trace")
|
||||
level, ok := logLevels[levelName]
|
||||
if !ok {
|
||||
fmt.Printf("Unknown log level: %s\n", levelName)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Unknown log level: %s\n", levelName)
|
||||
}
|
||||
|
||||
// Generate log configuration.
|
||||
@ -164,16 +163,14 @@ func newCacheService() {
|
||||
case "redis", "memcache":
|
||||
CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST"))
|
||||
default:
|
||||
fmt.Printf("Unknown cache adapter: %s\n", CacheAdapter)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Unknown cache adapter: %s\n", CacheAdapter)
|
||||
}
|
||||
|
||||
var err error
|
||||
Cache, err = cache.NewCache(CacheAdapter, CacheConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Init cache system failed, adapter: %s, config: %s, %v\n",
|
||||
qlog.Fatalf("Init cache system failed, adapter: %s, config: %s, %v\n",
|
||||
CacheAdapter, CacheConfig, err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
log.Info("Cache Service Enabled")
|
||||
@ -199,9 +196,8 @@ func newSessionService() {
|
||||
var err error
|
||||
SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Init session system failed, provider: %s, %v\n",
|
||||
qlog.Fatalf("Init session system failed, provider: %s, %v\n",
|
||||
SessionProvider, err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
log.Info("Session Service Enabled")
|
||||
@ -246,23 +242,20 @@ func NewConfigContext() {
|
||||
//var err error
|
||||
workDir, err := ExecDir()
|
||||
if err != nil {
|
||||
fmt.Printf("Fail to get work directory: %s\n", err)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Fail to get work directory: %s\n", err)
|
||||
}
|
||||
|
||||
cfgPath := filepath.Join(workDir, "conf/app.ini")
|
||||
Cfg, err = goconfig.LoadConfigFile(cfgPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
}
|
||||
Cfg.BlockMode = false
|
||||
|
||||
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
|
||||
if com.IsFile(cfgPath) {
|
||||
if err = Cfg.AppendFiles(cfgPath); err != nil {
|
||||
fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,8 +274,7 @@ func NewConfigContext() {
|
||||
}
|
||||
// Does not check run user when the install lock is off.
|
||||
if InstallLock && RunUser != curUser {
|
||||
fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
|
||||
}
|
||||
|
||||
LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
|
||||
@ -294,14 +286,14 @@ func NewConfigContext() {
|
||||
// Determine and create root git reposiroty path.
|
||||
homeDir, err := com.HomeDir()
|
||||
if err != nil {
|
||||
fmt.Printf("Fail to get home directory): %v\n", err)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Fail to get home directory): %v\n", err)
|
||||
}
|
||||
RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "git/gogs-repositories"))
|
||||
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
|
||||
fmt.Printf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
|
||||
os.Exit(2)
|
||||
qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
|
||||
}
|
||||
|
||||
log.Info("%s %s", AppName, AppVer)
|
||||
}
|
||||
|
||||
func NewServices() {
|
||||
|
@ -21,8 +21,6 @@ func init() {
|
||||
func NewLogger(bufLen int64, mode, config string) {
|
||||
Mode, Config = mode, config
|
||||
logger = logs.NewLogger(bufLen)
|
||||
logger.EnableFuncCallDepth(true)
|
||||
logger.SetLogFuncCallDepth(4)
|
||||
logger.SetLogger(mode, config)
|
||||
}
|
||||
|
||||
|
@ -6,13 +6,13 @@ package routers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Unknwon/goconfig"
|
||||
"github.com/go-martini/martini"
|
||||
"github.com/lunny/xorm"
|
||||
qlog "github.com/qiniu/log"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
@ -43,8 +43,7 @@ func GlobalInit() {
|
||||
|
||||
if base.InstallLock {
|
||||
if err := models.NewEngine(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(2)
|
||||
qlog.Fatal(err)
|
||||
}
|
||||
|
||||
models.HasEngine = true
|
||||
|
45
update.go
45
update.go
@ -6,7 +6,6 @@ package main
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@ -14,11 +13,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
qlog "github.com/qiniu/log"
|
||||
|
||||
"github.com/gogits/git"
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
//"github.com/qiniu/log"
|
||||
)
|
||||
|
||||
var CmdUpdate = cli.Command{
|
||||
@ -31,11 +30,15 @@ gogs serv provide access auth for repositories`,
|
||||
}
|
||||
|
||||
func newUpdateLogger(execDir string) {
|
||||
level := "0"
|
||||
logPath := execDir + "/log/update.log"
|
||||
os.MkdirAll(path.Dir(logPath), os.ModePerm)
|
||||
log.NewLogger(0, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, logPath))
|
||||
log.Trace("start logging...")
|
||||
f, err := os.Open(logPath)
|
||||
if err != nil {
|
||||
qlog.Fatal(err)
|
||||
}
|
||||
|
||||
qlog.SetOutput(f)
|
||||
qlog.Info("Start logging update...")
|
||||
}
|
||||
|
||||
// for command: ./gogs update
|
||||
@ -54,14 +57,12 @@ func runUpdate(c *cli.Context) {
|
||||
|
||||
args := c.Args()
|
||||
if len(args) != 3 {
|
||||
log.Error("received less 3 parameters")
|
||||
return
|
||||
qlog.Fatal("received less 3 parameters")
|
||||
}
|
||||
|
||||
refName := args[0]
|
||||
if refName == "" {
|
||||
log.Error("refName is empty, shouldn't use")
|
||||
return
|
||||
qlog.Fatal("refName is empty, shouldn't use")
|
||||
}
|
||||
oldCommitId := args[1]
|
||||
newCommitId := args[2]
|
||||
@ -69,8 +70,7 @@ func runUpdate(c *cli.Context) {
|
||||
isNew := strings.HasPrefix(oldCommitId, "0000000")
|
||||
if isNew &&
|
||||
strings.HasPrefix(newCommitId, "0000000") {
|
||||
log.Error("old rev and new rev both 000000")
|
||||
return
|
||||
qlog.Fatal("old rev and new rev both 000000")
|
||||
}
|
||||
|
||||
userName := os.Getenv("userName")
|
||||
@ -86,19 +86,18 @@ func runUpdate(c *cli.Context) {
|
||||
|
||||
repo, err := git.OpenRepository(f)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Open repoId: %v", err)
|
||||
return
|
||||
qlog.Fatalf("runUpdate.Open repoId: %v", err)
|
||||
}
|
||||
|
||||
newOid, err := git.NewOidFromString(newCommitId)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
newCommit, err := repo.LookupCommit(newOid)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -107,38 +106,38 @@ func runUpdate(c *cli.Context) {
|
||||
if isNew {
|
||||
l, err = repo.CommitsBefore(newCommit.Id())
|
||||
if err != nil {
|
||||
log.Error("Find CommitsBefore erro:", err)
|
||||
qlog.Fatalf("Find CommitsBefore erro:", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
oldOid, err := git.NewOidFromString(oldCommitId)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
oldCommit, err := repo.LookupCommit(oldOid)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
l = repo.CommitsBetween(newCommit, oldCommit)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Commit repoId: %v", err)
|
||||
qlog.Fatalf("runUpdate.Commit repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
sUserId, err := strconv.Atoi(userId)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Parse userId: %v", err)
|
||||
qlog.Fatalf("runUpdate.Parse userId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
repos, err := models.GetRepositoryByName(int64(sUserId), repoName)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.GetRepositoryByName userId: %v", err)
|
||||
qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -163,6 +162,6 @@ func runUpdate(c *cli.Context) {
|
||||
//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
|
||||
if err = models.CommitRepoAction(int64(sUserId), userName, actEmail,
|
||||
repos.Id, repoName, git.BranchName(refName), &base.PushCommits{l.Len(), commits}); err != nil {
|
||||
log.Error("runUpdate.models.CommitRepoAction: %v", err)
|
||||
qlog.Fatalf("runUpdate.models.CommitRepoAction: %v", err)
|
||||
}
|
||||
}
|
||||
|
8
web.go
8
web.go
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/go-martini/martini"
|
||||
qlog "github.com/qiniu/log"
|
||||
|
||||
"github.com/gogits/binding"
|
||||
|
||||
@ -50,9 +51,7 @@ func newMartini() *martini.ClassicMartini {
|
||||
}
|
||||
|
||||
func runWeb(*cli.Context) {
|
||||
fmt.Println("Server is running...")
|
||||
routers.GlobalInit()
|
||||
log.Info("%s %s", base.AppName, base.AppVer)
|
||||
|
||||
m := newMartini()
|
||||
|
||||
@ -177,14 +176,13 @@ func runWeb(*cli.Context) {
|
||||
if protocol == "http" {
|
||||
log.Info("Listen: http://%s", listenAddr)
|
||||
if err := http.ListenAndServe(listenAddr, m); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
//log.Critical(err.Error()) // not working now
|
||||
qlog.Error(err.Error())
|
||||
}
|
||||
} else if protocol == "https" {
|
||||
log.Info("Listen: https://%s", listenAddr)
|
||||
if err := http.ListenAndServeTLS(listenAddr, base.Cfg.MustValue("server", "CERT_FILE"),
|
||||
base.Cfg.MustValue("server", "KEY_FILE"), m); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
qlog.Error(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user