diff options
author | zeripath <art27@cantab.net> | 2022-06-24 11:49:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-24 12:49:47 +0200 |
commit | 4909493a9f75ad188f044b8577e7357f122fb445 (patch) | |
tree | 56d3c97df67b0a0846bbb9a92ebd4fb1e90ab4e4 /modules/private | |
parent | afea63f4e5a4b7e3da03a7d5fc6590569976e7d3 (diff) | |
download | gitea-4909493a9f75ad188f044b8577e7357f122fb445.tar.gz gitea-4909493a9f75ad188f044b8577e7357f122fb445.zip |
Allow manager logging to set SQL (#20064)
This PR adds a new manager command to switch on SQL logging and to turn it off.
```
gitea manager logging log-sql
gitea manager logging log-sql --off
```
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/private')
-rw-r--r-- | modules/private/manager.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/private/manager.go b/modules/private/manager.go index 8405bf2c83..ba51260ebb 100644 --- a/modules/private/manager.go +++ b/modules/private/manager.go @@ -10,6 +10,7 @@ import ( "io" "net/http" "net/url" + "strconv" "time" "code.gitea.io/gitea/modules/json" @@ -139,6 +140,24 @@ func ReleaseReopenLogging(ctx context.Context) (int, string) { return http.StatusOK, "Logging Restarted" } +// SetLogSQL sets database logging +func SetLogSQL(ctx context.Context, on bool) (int, string) { + reqURL := setting.LocalURL + "api/internal/manager/set-log-sql?on=" + strconv.FormatBool(on) + + req := newInternalRequest(ctx, reqURL, "POST") + resp, err := req.Response() + if err != nil { + return http.StatusInternalServerError, fmt.Sprintf("Unable to contact gitea: %v", err.Error()) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return resp.StatusCode, decodeJSONError(resp).Err + } + + return http.StatusOK, "Log SQL setting set" +} + // LoggerOptions represents the options for the add logger call type LoggerOptions struct { Group string |