Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update go versions to go1.19, go1.20, go1.21, and add go.mod #114

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
15 changes: 4 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ jobs:
strategy:
matrix:
os: [ubuntu, macos, windows]
golang: ['1.13', '1.16', '1.17']
# currently, we cannot run non-x86_64 machines on Github Actions cloud env.
golang: ['1.19', '1.20', '1.21']
# currently, we cannot run non-x86_64 machines on GitHub Actions cloud env.
runs-on: ${{ matrix.os }}-latest
name: CI golang ${{ matrix.golang }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.golang }}
- name: Change GO11MODULES
run: go env -w GO111MODULE=auto
- name: Install requirements
run: |
go get github.com/bmizerany/assert
go get github.com/philhofer/fwd
go get github.com/tinylib/msgp
- name: Test
run: go test -v ./fluent
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ fluent-logger-golang

## How to install

```
go get github.com/fluent/fluent-logger-golang/fluent
```bash
go get github.com/fluent/fluent-logger-golang/fluent@latest
```

## Usage

Install the package with `go get` and use `import` to include it in your project.

```
```go
import "github.com/fluent/fluent-logger-golang/fluent"
```

Expand All @@ -26,27 +26,32 @@ import "github.com/fluent/fluent-logger-golang/fluent"
package main

import (
"github.com/fluent/fluent-logger-golang/fluent"
"fmt"
//"time"
"fmt"
"time"

"github.com/fluent/fluent-logger-golang/fluent"
)

func main() {
logger, err := fluent.New(fluent.Config{})
if err != nil {
fmt.Println(err)
}
defer logger.Close()
tag := "myapp.access"
var data = map[string]string{
"foo": "bar",
"hoge": "hoge",
}
error := logger.Post(tag, data)
// error := logger.PostWithTime(tag, time.Now(), data)
if error != nil {
panic(error)
}
logger, err := fluent.New(fluent.Config{})
if err != nil {
fmt.Println(err)
}
defer logger.Close()
tag := "myapp.access"
data := map[string]string{
"foo": "bar",
"hoge": "hoge",
}
err = logger.Post(tag, data)
if err != nil {
panic(err)
}

err = logger.PostWithTime(tag, time.Now(), data)
if err != nil {
panic(err)
}
}
```

Expand Down Expand Up @@ -181,7 +186,7 @@ were involved. Starting v1.8.0, the logger no longer accepts `Fluent.Post()`
after `Fluent.Close()`, and instead returns a "Logger already closed" error.

## Tests
```

```bash
go test
```
7 changes: 4 additions & 3 deletions _examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"../fluent"
"github.com/fluent/fluent-logger-golang/fluent"
)

func main() {
Expand All @@ -15,9 +15,10 @@ func main() {
}
defer logger.Close()
tag := "myapp.access"
var data = map[string]string{
data := map[string]string{
"foo": "bar",
"hoge": "hoge"}
"hoge": "hoge",
}
for i := 0; i < 100; i++ {
e := logger.Post(tag, data)
if e != nil {
Expand Down
49 changes: 22 additions & 27 deletions fluent/fluent.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package fluent

import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
Expand All @@ -15,10 +18,6 @@ import (
"sync"
"time"

"bytes"
"encoding/base64"
"encoding/binary"

"github.com/tinylib/msgp/msgp"
)

Expand All @@ -34,9 +33,6 @@ const (
defaultMaxRetryWait = 60000
defaultMaxRetry = 13
defaultReconnectWaitIncreRate = 1.5
// Default sub-second precision value to false since it is only compatible
// with fluentd versions v0.14 and above.
defaultSubSecondPrecision = false

// Default value whether to skip checking insecure certs on TLS connections.
defaultTlsInsecureSkipVerify = false
Expand Down Expand Up @@ -200,27 +196,26 @@ func newWithDialer(config Config, d dialer) (f *Fluent, err error) {
//
// Examples:
//
// // send map[string]
// mapStringData := map[string]string{
// "foo": "bar",
// }
// f.Post("tag_name", mapStringData)
//
// // send message with specified time
// mapStringData := map[string]string{
// "foo": "bar",
// }
// tm := time.Now()
// f.PostWithTime("tag_name", tm, mapStringData)
// // send map[string]
// mapStringData := map[string]string{
// "foo": "bar",
// }
// f.Post("tag_name", mapStringData)
//
// // send struct
// structData := struct {
// Name string `msg:"name"`
// } {
// "john smith",
// }
// f.Post("tag_name", structData)
// // send message with specified time
// mapStringData := map[string]string{
// "foo": "bar",
// }
// tm := time.Now()
// f.PostWithTime("tag_name", tm, mapStringData)
//
// // send struct
// structData := struct {
// Name string `msg:"name"`
// } {
// "john smith",
// }
// f.Post("tag_name", structData)
func (f *Fluent) Post(tag string, message interface{}) error {
timeNow := time.Now()
return f.PostWithTime(tag, timeNow, message)
Expand Down Expand Up @@ -317,7 +312,7 @@ func (chunk *MessageChunk) MarshalJSON() ([]byte, error) {
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf("[\"%s\",%d,%s,%s]", chunk.message.Tag,
return []byte(fmt.Sprintf(`["%s",%d,%s,%s]`, chunk.message.Tag,
chunk.message.Time, data, option)), err
}

Expand Down