mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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>
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user