mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(logging): replace all the loggers with zerolog EE-4186 (#7663)
This commit is contained in:
parent
53025178ef
commit
36e7981ab7
109 changed files with 1101 additions and 662 deletions
|
@ -1,16 +1,15 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/http/proxy/factory/utils"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
"github.com/portainer/portainer/api/internal/stackutils"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -79,7 +78,11 @@ func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject m
|
|||
for _, name := range teamNames {
|
||||
team, err := transport.dataStore.Team().TeamByName(name)
|
||||
if err != nil {
|
||||
log.Printf("[WARN] [http,proxy,docker] [message: unknown team name in access control label, ignoring access control rule for this team] [name: %s] [resource_id: %s]", name, resourceID)
|
||||
log.Warn().
|
||||
Str("name", name).
|
||||
Str("resource_id", resourceID).
|
||||
Msg("unknown team name in access control label, ignoring access control rule for this team")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -89,7 +92,11 @@ func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject m
|
|||
for _, name := range userNames {
|
||||
user, err := transport.dataStore.User().UserByUsername(name)
|
||||
if err != nil {
|
||||
log.Printf("[WARN] [http,proxy,docker] [message: unknown user name in access control label, ignoring access control rule for this user] [name: %s] [resource_id: %s]", name, resourceID)
|
||||
log.Warn().
|
||||
Str("name", name).
|
||||
Str("resource_id", resourceID).
|
||||
Msg("unknown user name in access control label, ignoring access control rule for this user")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -114,7 +121,11 @@ func (transport *Transport) createPrivateResourceControl(resourceIdentifier stri
|
|||
|
||||
err := transport.dataStore.ResourceControl().Create(resourceControl)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] [http,proxy,docker,transport] [message: unable to persist resource control] [resource: %s] [err: %s]", resourceIdentifier, err)
|
||||
log.Error().
|
||||
Str("resource", resourceIdentifier).
|
||||
Err(err).
|
||||
Msg("unable to persist resource control")
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -148,7 +159,10 @@ func (transport *Transport) getInheritedResourceControlFromServiceOrStack(resour
|
|||
|
||||
func (transport *Transport) applyAccessControlOnResource(parameters *resourceOperationParameters, responseObject map[string]interface{}, response *http.Response, executor *operationExecutor) error {
|
||||
if responseObject[parameters.resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[WARN] [message: unable to find resource identifier property in resource object] [identifier_attribute: %s]", parameters.resourceIdentifierAttribute)
|
||||
log.Warn().
|
||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||
Msg("unable to find resource identifier property in resource object")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -195,7 +209,10 @@ func (transport *Transport) decorateResourceList(parameters *resourceOperationPa
|
|||
resourceObject := resource.(map[string]interface{})
|
||||
|
||||
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[WARN] [http,proxy,docker,decorate] [message: unable to find resource identifier property in resource list element] [identifier_attribute: %s]", parameters.resourceIdentifierAttribute)
|
||||
log.Warn().
|
||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||
Msg("unable to find resource identifier property in resource list element")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -232,7 +249,10 @@ func (transport *Transport) filterResourceList(parameters *resourceOperationPara
|
|||
for _, resource := range resourceData {
|
||||
resourceObject := resource.(map[string]interface{})
|
||||
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[WARN] [http,proxy,docker,filter] [message: unable to find resource identifier property in resource list element] [identifier_attribute: %s]", parameters.resourceIdentifierAttribute)
|
||||
log.Warn().
|
||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||
Msg("unable to find resource identifier property in resource list element")
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime"
|
||||
"net/http"
|
||||
|
||||
"github.com/portainer/portainer/api/archive"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const OneMegabyte = 1024768
|
||||
|
@ -78,7 +79,7 @@ func buildOperation(request *http.Request) error {
|
|||
|
||||
defer f.Close()
|
||||
|
||||
log.Printf("[INFO] [http,proxy,docker] [message: upload the file to build image] [filename: %s] [size: %d]", hdr.Filename, hdr.Size)
|
||||
log.Info().Str("filename", hdr.Filename).Int64("size", hdr.Size).Msg("upload the file to build image")
|
||||
|
||||
content, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"regexp"
|
||||
|
@ -21,6 +20,8 @@ import (
|
|||
"github.com/portainer/portainer/api/http/proxy/factory/utils"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var apiVersionRe = regexp.MustCompile(`(/v[0-9]\.[0-9]*)?`)
|
||||
|
@ -422,6 +423,7 @@ func (transport *Transport) proxyImageRequest(request *http.Request) (*http.Resp
|
|||
|
||||
func (transport *Transport) replaceRegistryAuthenticationHeader(request *http.Request) (*http.Response, error) {
|
||||
transport.decorateRegistryAuthenticationHeader(request)
|
||||
|
||||
return transport.decorateGenericResourceCreationOperation(request, serviceObjectIdentifier, portainer.ServiceResourceControl)
|
||||
}
|
||||
|
||||
|
@ -601,7 +603,8 @@ func (transport *Transport) decorateGenericResourceCreationResponse(response *ht
|
|||
}
|
||||
|
||||
if responseObject[resourceIdentifierAttribute] == nil {
|
||||
log.Printf("[ERROR] [proxy,docker]")
|
||||
log.Error().Msg("missing identifier in Docker resource creation response")
|
||||
|
||||
return errors.New("missing identifier in Docker resource creation response")
|
||||
}
|
||||
|
||||
|
@ -754,6 +757,7 @@ func (transport *Transport) createOperationContext(request *http.Request) (*rest
|
|||
for _, membership := range teamMemberships {
|
||||
userTeamIDs = append(userTeamIDs, membership.TeamID)
|
||||
}
|
||||
|
||||
operationContext.userTeamIDs = userTeamIDs
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue