Skip to content

Commit

Permalink
properly implementation AZBLOB_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
Slach committed Aug 28, 2024
1 parent 06abf06 commit 0c63e72
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions pkg/storage/azblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ func (a *AzureBlob) logf(msg string, args ...interface{}) {
log.Debug().Msgf(msg, args...)
}
}

func (a *AzureBlob) log(level pipeline.LogLevel, msg string) {
if a.Config.Debug {
switch level {
case pipeline.LogNone:
log.Debug().Msg(msg)
case pipeline.LogFatal:
log.Fatal().Msg(msg)
case pipeline.LogPanic:
log.Fatal().Msg(msg)
case pipeline.LogError:
log.Error().Msg(msg)
case pipeline.LogWarning:
log.Warn().Msg(msg)
case pipeline.LogInfo:
log.Info().Msg(msg)
case pipeline.LogDebug:
log.Debug().Msg(msg)
}
}
}

func (a *AzureBlob) Kind() string {
return "azblob"
}
Expand Down Expand Up @@ -116,11 +138,20 @@ func (a *AzureBlob) Connect(ctx context.Context) error {
case <-ctx.Done():
return ctx.Err()
default:
a.Pipeline = azblob.NewPipeline(credential, azblob.PipelineOptions{
options := azblob.PipelineOptions{
Retry: azblob.RetryOptions{
TryTimeout: timeout,
},
})
}
if a.Config.Debug {
options.Log = pipeline.LogOptions{
Log: a.log,
ShouldLog: func(level pipeline.LogLevel) bool {
return true
},
}
}
a.Pipeline = azblob.NewPipeline(credential, options)
a.Container = azblob.NewServiceURL(*u, a.Pipeline).NewContainerURL(a.Config.Container)
_, err = a.Container.Create(ctx, azblob.Metadata{}, azblob.PublicAccessNone)
if err != nil && !isContainerAlreadyExists(err) {
Expand Down

0 comments on commit 0c63e72

Please sign in to comment.