Skip to content

Commit

Permalink
Merge pull request #167 from mashiike/feature/bypass-s3-select-logger
Browse files Browse the repository at this point in the history
bypass s3 select sql driver logger
  • Loading branch information
mashiike authored Oct 3, 2023
2 parents fdde14d + 0a5823a commit 77a6723
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion provider/s3select/s3select.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,50 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"log/slog"
"net/url"
"os"
"strings"
"sync"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/mashiike/prepalert/provider"
"github.com/mashiike/prepalert/provider/sqlprovider"
_ "github.com/mashiike/s3-select-sql-driver"
s3select "github.com/mashiike/s3-select-sql-driver"
)

var (
defaultExpressionExpr hcl.Expression
)

type bypassLogger struct {
Level slog.Level
Impl *slog.Logger
once sync.Once
}

func (l *bypassLogger) Printf(format string, v ...any) {
l.once.Do(func() {
l.Impl = slog.Default().With("component", "s3-select-sql-driver")
})
l.Impl.Log(context.Background(), l.Level, fmt.Sprintf(format, v...))
}

func (l *bypassLogger) SetOutput(w io.Writer) {}
func (l *bypassLogger) Writer() io.Writer { return io.Discard }

func init() {
provider.RegisterProvider("s3_select", NewProvider)
var diags hcl.Diagnostics
defaultExpressionExpr, diags = hclsyntax.ParseExpression([]byte(`"SELECT * FROM s3object s"`), "expression.hcl", hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
panic(diags)
}
s3select.SetLogger(&bypassLogger{Level: slog.LevelError})
s3select.SetDebugLogger(&bypassLogger{Level: slog.LevelDebug})
}

type Provider struct {
Expand Down

0 comments on commit 77a6723

Please sign in to comment.