fix: aws fixed logger level to debug

This commit is contained in:
RouxAntoine 2021-03-12 02:04:54 +01:00
parent b4d8317e93
commit fe8cc087c0
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
5 changed files with 30 additions and 15 deletions

View File

@ -40,7 +40,11 @@ ARG BINARYNAME="poller"
COPY . . COPY . .
# RUN make build-$BINARYNAME GOARCH=$TARGETARCH GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) LDFLAGS='-extldflags="-static"' # RUN make build-$BINARYNAME GOARCH=$TARGETARCH GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) LDFLAGS='-extldflags="-static"'
RUN make build-$BINARYNAME GOARCH=$TARGETARCH GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) GOBUILDFLAGS="-a -tags netgo -installsuffix netgo" RUN make build-$BINARYNAME \
GOARCH=$TARGETARCH \
GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) \
GOBUILDFLAGS="-a -tags netgo -installsuffix netgo" \
LDFLAGS="-w -s -d"
FROM scratch FROM scratch

View File

@ -3,9 +3,9 @@
GOARCH=amd64 GOARCH=amd64
# GOARCH=arm # GOARCH=arm
GOOS=linux GOOS=darwin
# GOOS=darwin # GOOS=linux
LDFLAGS=-w -s -d LDFLAGS=-w -s
GOBUILDFLAGS= GOBUILDFLAGS=
DOCKER_BUILDKIT=1 DOCKER_BUILDKIT=1
CGO_ENABLED=0 CGO_ENABLED=0

View File

@ -42,7 +42,7 @@ func NewWeatherPoller(log *logger.WeatherLogger, remote web.ListenAddr, lat, lon
//Poll retrieve weather information //Poll retrieve weather information
func (w *weatherPoller) Poll() io.ReadCloser { func (w *weatherPoller) Poll() io.ReadCloser {
r, err := w.client.Get(w.endpoint.String()) r, err := w.client.Get(w.endpoint.String())
w.logger.Debug("HTTP poll to openweathermap", w.logger.Info("HTTP poll to openweathermap",
zap.Int("http.response.status_code", r.StatusCode), zap.Int("http.response.status_code", r.StatusCode),
zap.Int("http.response.body.bytes", int(r.ContentLength)), zap.Int("http.response.body.bytes", int(r.ContentLength)),
) )

View File

@ -57,22 +57,22 @@ func NewS3Storage(log *logger.WeatherLogger, config *WeatherS3StorageConfig, buc
s3.handleError(err) s3.handleError(err)
consolidateConfig = aws.Config{ consolidateConfig = aws.Config{
Endpoint: &customConfig.Default.EndpointURL, Endpoint: &customConfig.Default.EndpointURL,
DisableSSL: aws.Bool(true),
LogLevel: aws.LogLevel(aws.LogDebug),
S3ForcePathStyle: aws.Bool(true),
} }
} else { } else {
consolidateConfig = aws.Config{ consolidateConfig = aws.Config{
Endpoint: &config.EndpointURL, Endpoint: &config.EndpointURL,
Credentials: credentials.NewStaticCredentials(config.AwsAccessKeyID, config.AwsSecretAccessKey, ""), Credentials: credentials.NewStaticCredentials(config.AwsAccessKeyID, config.AwsSecretAccessKey, ""),
Region: &config.Region, Region: &config.Region,
DisableSSL: aws.Bool(true),
LogLevel: aws.LogLevel(aws.LogDebug),
S3ForcePathStyle: aws.Bool(true),
} }
} }
consolidateConfig.MergeIn(&aws.Config{
DisableSSL: aws.Bool(true),
LogLevel: aws.LogLevel(log.GetAwsLevel()),
S3ForcePathStyle: aws.Bool(true),
})
s, err := session.NewSessionWithOptions(session.Options{ s, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable, SharedConfigState: session.SharedConfigEnable,
Config: consolidateConfig, Config: consolidateConfig,

View File

@ -10,6 +10,7 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
"github.com/aws/aws-sdk-go/aws"
"go.elastic.co/apm/module/apmzap" "go.elastic.co/apm/module/apmzap"
"go.elastic.co/ecszap" "go.elastic.co/ecszap"
"go.uber.org/zap" "go.uber.org/zap"
@ -152,3 +153,13 @@ func (wl *WeatherLogger) handleError(err error) {
wl.Logger.Fatal("Logger error", zap.Error(err)) wl.Logger.Fatal("Logger error", zap.Error(err))
} }
} }
//GetAwsLevelnconvert log zapcore.Level to aws.LogLevelType
func (wl *WeatherLogger) GetAwsLevel() aws.LogLevelType {
switch wl.Level.Level() {
case zapcore.DebugLevel:
return aws.LogDebug
default:
return aws.LogOff
}
}