diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-09-29 22:26:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-29 22:26:07 +0800 |
commit | 7bc3ee49aa317e48331cf6e39e1911ac89b2e325 (patch) | |
tree | 8d5a515c79061e67f2164e696c189a8d99ce0fcd /internal/cmd | |
parent | 8fc40132401747dbd2a39dbb6869eb1652a2f882 (diff) |
cmd/serv: use different log files for ORMs in hook mode (#6361)
Diffstat (limited to 'internal/cmd')
-rw-r--r-- | internal/cmd/hook.go | 6 | ||||
-rw-r--r-- | internal/cmd/serv.go | 7 |
2 files changed, 7 insertions, 6 deletions
diff --git a/internal/cmd/hook.go b/internal/cmd/hook.go index 9b4e2278..99a5e15b 100644 --- a/internal/cmd/hook.go +++ b/internal/cmd/hook.go @@ -66,7 +66,7 @@ func runHookPreReceive(c *cli.Context) error { if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 { return nil } - setup(c, "hooks/pre-receive.log", true) + setup(c, "pre-receive.log", true) isWiki := strings.Contains(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/") @@ -159,7 +159,7 @@ func runHookUpdate(c *cli.Context) error { if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 { return nil } - setup(c, "hooks/update.log", false) + setup(c, "update.log", false) args := c.Args() if len(args) != 3 { @@ -193,7 +193,7 @@ func runHookPostReceive(c *cli.Context) error { if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 { return nil } - setup(c, "hooks/post-receive.log", true) + setup(c, "post-receive.log", true) // Post-receive hook does more than just gather Git information, // so we need to setup additional services for email notifications. diff --git a/internal/cmd/serv.go b/internal/cmd/serv.go index 4c9bb4ca..06d78a6d 100644 --- a/internal/cmd/serv.go +++ b/internal/cmd/serv.go @@ -38,7 +38,7 @@ var Serv = cli.Command{ // logs error message on the server side. When not in "prod" mode, // error message is also printed to the client for easier debugging. func fail(userMessage, errMessage string, args ...interface{}) { - fmt.Fprintln(os.Stderr, "Gogs:", userMessage) + _, _ = fmt.Fprintln(os.Stderr, "Gogs:", userMessage) if len(errMessage) > 0 { if !conf.IsProdMode() { @@ -47,10 +47,11 @@ func fail(userMessage, errMessage string, args ...interface{}) { log.Error(errMessage, args...) } + log.Stop() os.Exit(1) } -func setup(c *cli.Context, logPath string, connectDB bool) { +func setup(c *cli.Context, logFile string, connectDB bool) { conf.HookMode = true var customConf string @@ -73,7 +74,7 @@ func setup(c *cli.Context, logPath string, connectDB bool) { err = log.NewFile(log.FileConfig{ Level: level, - Filename: filepath.Join(conf.Log.RootPath, logPath), + Filename: filepath.Join(conf.Log.RootPath, "hooks", logFile), FileRotationConfig: log.FileRotationConfig{ Rotate: true, Daily: true, |