Skip to content

Commit e56e63e

Browse files
feat: added logging
1 parent 5bbcc4a commit e56e63e

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Others
44

55
1. [#68](https://github.com/InfluxCommunity/influxdb3-go/pull/68): Upgrade Go version to 1.22.
6+
2. [#74](https://github.com/InfluxCommunity/influxdb3-go/pull/74): Added logger.
67

78
## 0.6.0 [2024-03-01]
89

influxdb3/client.go

+9
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ import (
2828
"encoding/json"
2929
"fmt"
3030
"io"
31+
"log/slog"
3132
"mime"
3233
"net/http"
3334
"net/url"
35+
"os"
3436
"path"
3537
"strconv"
3638
"strings"
3739

3840
"github.com/apache/arrow/go/v15/arrow/flight"
3941
)
4042

43+
var logger *slog.Logger
44+
4145
// Client implements an InfluxDB client.
4246
type Client struct {
4347
// Configuration options.
@@ -107,6 +111,11 @@ func New(config ClientConfig) (*Client, error) {
107111
return nil, fmt.Errorf("flight client: %w", err)
108112
}
109113

114+
// Initialize logger
115+
logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
116+
Level: c.config.LogLevel,
117+
}))
118+
110119
return c, nil
111120
}
112121

influxdb3/config.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ package influxdb3
2525
import (
2626
"errors"
2727
"fmt"
28-
"github.com/influxdata/line-protocol/v2/lineprotocol"
28+
"log/slog"
2929
"net/http"
3030
"net/url"
3131
"os"
3232
"strconv"
33+
34+
"github.com/influxdata/line-protocol/v2/lineprotocol"
3335
)
3436

3537
const (
@@ -74,6 +76,9 @@ type ClientConfig struct {
7476

7577
// Default HTTP headers to be included in requests
7678
Headers http.Header
79+
80+
// LogLevel for the logger
81+
LogLevel slog.Leveler
7782
}
7883

7984
// validate validates the config.

influxdb3/point_values.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (pv *PointValues) SetTimestamp(timestamp time.Time) *PointValues {
7070
// SetTag sets a tag value and returns the modified PointValues
7171
func (pv *PointValues) SetTag(name string, value string) *PointValues {
7272
if value == "" {
73-
fmt.Printf("Empty tags has no effect, tag [%s], measurement [%s]\n", name, pv.MeasurementName)
73+
logger.Debug(fmt.Sprintf("Empty tags has no effect, tag [%s], measurement [%s]", name, pv.MeasurementName))
7474
} else {
7575
pv.Tags[name] = value
7676
}

0 commit comments

Comments
 (0)