mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
refact: logrus.GetLevel() -> logrus.IsLevelEnabled() (#3579)
This commit is contained in:
parent
a0fab0ac5a
commit
7396a103d0
7 changed files with 14 additions and 14 deletions
|
@ -92,7 +92,7 @@ func (t *JWTTransport) refreshJwtToken() error {
|
|||
req.Header.Add("User-Agent", t.UserAgent)
|
||||
}
|
||||
|
||||
if log.GetLevel() >= log.TraceLevel {
|
||||
if log.IsLevelEnabled(log.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, true)
|
||||
log.Tracef("auth-jwt request: %s", string(dump))
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func (t *JWTTransport) refreshJwtToken() error {
|
|||
|
||||
log.Debugf("auth-jwt : http %d", resp.StatusCode)
|
||||
|
||||
if log.GetLevel() >= log.TraceLevel {
|
||||
if log.IsLevelEnabled(log.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, true)
|
||||
log.Tracef("auth-jwt response: %s", string(dump))
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ func (t *JWTTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
attemptsCount := make(map[int]int)
|
||||
|
||||
for {
|
||||
if log.GetLevel() >= log.TraceLevel {
|
||||
if log.IsLevelEnabled(log.TraceLevel) {
|
||||
// requestToDump := cloneRequest(req)
|
||||
dump, _ := httputil.DumpRequest(req, true)
|
||||
log.Tracef("req-jwt: %s", string(dump))
|
||||
|
|
|
@ -37,7 +37,7 @@ func (t *APIKeyTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
|
||||
log.Debugf("req-api: %s %s", req.Method, req.URL.String())
|
||||
|
||||
if log.GetLevel() >= log.TraceLevel {
|
||||
if log.IsLevelEnabled(log.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, true)
|
||||
log.Tracef("auth-api request: %s", string(dump))
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func (t *APIKeyTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
return resp, err
|
||||
}
|
||||
|
||||
if log.GetLevel() >= log.TraceLevel {
|
||||
if log.IsLevelEnabled(log.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, true)
|
||||
log.Tracef("auth-api response: %s", string(dump))
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (c *ApiClient) PrepareRequest(ctx context.Context, method, url string, body interface{}) (*http.Request, error) {
|
||||
func (c *ApiClient) PrepareRequest(ctx context.Context, method, url string, body any) (*http.Request, error) {
|
||||
if !strings.HasSuffix(c.BaseURL.Path, "/") {
|
||||
return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL)
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func (c *ApiClient) PrepareRequest(ctx context.Context, method, url string, body
|
|||
return req, nil
|
||||
}
|
||||
|
||||
func (c *ApiClient) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) {
|
||||
func (c *ApiClient) Do(ctx context.Context, req *http.Request, v any) (*Response, error) {
|
||||
if ctx == nil {
|
||||
return nil, errors.New("context must be non-nil")
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func (c *ApiClient) Do(ctx context.Context, req *http.Request, v interface{}) (*
|
|||
return newResponse(resp), err
|
||||
}
|
||||
|
||||
if log.GetLevel() >= log.DebugLevel {
|
||||
if log.IsLevelEnabled(log.DebugLevel) {
|
||||
for k, v := range resp.Header {
|
||||
log.Debugf("[headers] %s: %s", k, v)
|
||||
}
|
||||
|
|
|
@ -730,7 +730,7 @@ func (a *apic) UpdateAllowlists(ctx context.Context, allowlistsLinks []*modelsca
|
|||
}
|
||||
|
||||
for _, link := range allowlistsLinks {
|
||||
if log.GetLevel() >= log.TraceLevel {
|
||||
if log.IsLevelEnabled(log.TraceLevel) {
|
||||
log.Tracef("allowlist body: %+v", spew.Sdump(link))
|
||||
}
|
||||
|
||||
|
@ -773,6 +773,7 @@ func (a *apic) UpdateAllowlists(ctx context.Context, allowlistsLinks []*modelsca
|
|||
for scanner.Scan() {
|
||||
item := scanner.Text()
|
||||
j := &models.AllowlistItem{}
|
||||
|
||||
if err := json.Unmarshal([]byte(item), j); err != nil {
|
||||
log.Errorf("while unmarshalling allowlist item: %s", err)
|
||||
continue
|
||||
|
|
|
@ -178,7 +178,7 @@ func NewServer(ctx context.Context, config *csconfig.LocalApiServerCfg) (*APISer
|
|||
}
|
||||
}
|
||||
|
||||
if log.GetLevel() < log.DebugLevel {
|
||||
if !log.IsLevelEnabled(log.DebugLevel) {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
|
|
|
@ -459,9 +459,9 @@ func (t *HubTestItem) RunWithLogFile() error {
|
|||
crowdsecCmd.Env = []string{"TESTDIR="+testPath, "DATADIR="+t.RuntimeHubConfig.InstallDataDir, "TZ=UTC"}
|
||||
|
||||
log.Debugf("%s", crowdsecCmd.String())
|
||||
output, err = crowdsecCmd.CombinedOutput()
|
||||
|
||||
if log.GetLevel() >= log.DebugLevel || err != nil {
|
||||
output, err = crowdsecCmd.CombinedOutput()
|
||||
if err != nil || log.IsLevelEnabled(log.DebugLevel) {
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
|
||||
|
|
|
@ -143,8 +143,7 @@ func (a *Alert) FormatAsStrings(machineID string, logger *log.Logger) []string {
|
|||
decision = "(simulated decision)"
|
||||
}
|
||||
|
||||
if logger.GetLevel() >= log.DebugLevel {
|
||||
/*spew is expensive*/
|
||||
if logger.IsLevelEnabled(log.DebugLevel) {
|
||||
logger.Debug(spew.Sdump(decisionItem))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue