Skip to content

Commit

Permalink
Merge pull request #1 from SGNL-ai/sc-959-add-zap-syslog-dependencies
Browse files Browse the repository at this point in the history
sc-959-sgnl-syslog-lib-update
  • Loading branch information
haoyu-sgnl authored Oct 31, 2022
2 parents e6342db + e3d16c8 commit 0388bf1
Show file tree
Hide file tree
Showing 10 changed files with 402 additions and 466 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go:
- '1.8.x'
- '1.9.x'
- '1.10.x'
go_import_path: github.com/yumm007/zap-syslog
go_import_path: github.com/SGNL-ai/zap-syslog
cache:
directories:
- vendor
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# zap-syslog

SGNL zap syslog library

[![GoDoc](https://godoc.org/github.com/imperfectgo/zap-syslog?status.svg)](https://godoc.org/github.com/imperfectgo/zap-syslog)
[![Build Status](https://travis-ci.org/imperfectgo/zap-syslog.svg?branch=master)](https://travis-ci.org/imperfectgo/zap-syslog)
[![Go Report Card](https://goreportcard.com/badge/github.com/imperfectgo/zap-syslog)](https://goreportcard.com/report/github.com/imperfectgo/zap-syslog)
Expand Down
7 changes: 4 additions & 3 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
package zapsyslog

import (
"github.com/yumm007/zap-syslog/internal"
"github.com/yumm007/zap-syslog/internal/bufferpool"
"github.com/yumm007/zap-syslog/syslog"
"os"
"path"
"strings"
"time"

"github.com/SGNL-ai/zap-syslog/internal"
"github.com/SGNL-ai/zap-syslog/internal/bufferpool"
"github.com/SGNL-ai/zap-syslog/syslog"

"go.uber.org/zap"
"go.uber.org/zap/buffer"
"go.uber.org/zap/zapcore"
Expand Down
712 changes: 356 additions & 356 deletions encoder_test.go

Large diffs are not rendered by default.

40 changes: 0 additions & 40 deletions example/docker-compose.yml

This file was deleted.

7 changes: 4 additions & 3 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"crypto/rand"
"encoding/hex"
"github.com/yumm007/zap-syslog"
"github.com/yumm007/zap-syslog/syslog"
"os"

zapsyslog "github.com/SGNL-ai/zap-syslog"
"github.com/SGNL-ai/zap-syslog/syslog"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand All @@ -30,7 +31,7 @@ func main() {
App: "zapsyslog-test",
})

sink, err := zapsyslog.NewConnSyncer("tcp", "localhost:514")
sink, err := zapsyslog.NewConnSyncer("tcp", "localhost:514", true)
if err != nil {
panic(err)
}
Expand Down
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module github.com/yumm007/zap-syslog
module github.com/SGNL-ai/zap-syslog

go 1.17
go 1.18

require (
github.com/stretchr/testify v1.7.0
go.uber.org/multierr v1.7.0
go.uber.org/zap v1.21.0
github.com/stretchr/testify v1.8.1
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.23.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
github.com/stretchr/objx v0.5.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
62 changes: 16 additions & 46 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,61 +1,31 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 4 additions & 3 deletions syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
package zapsyslog

import (
"go.uber.org/atomic"
"net"
"strings"

"go.uber.org/atomic"

"go.uber.org/zap/zapcore"
)

Expand Down Expand Up @@ -79,7 +80,7 @@ func (s *ConnSyncer) close() {

// connect makes a connection to the syslog server.
func (s *ConnSyncer) connect() error {
if s.enabled.Load() == false {
if !s.enabled.Load() {
return nil
}
s.close()
Expand All @@ -106,7 +107,7 @@ func (s *ConnSyncer) connect() error {

// Write writes to syslog with retry.
func (s *ConnSyncer) Write(p []byte) (n int, err error) {
if s.enabled.Load() == false {
if !s.enabled.Load() {
s.close()
return n, nil
}
Expand Down
14 changes: 7 additions & 7 deletions syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package zapsyslog
import (
"bufio"
"io"
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -100,7 +99,8 @@ func startServer(n, la string, done chan<- string) (addr string, sock io.Closer,
// unix and unixgram: choose an address if none given
if la == "" {
// use ioutil.TempFile to get a name that is unique
f, err := ioutil.TempFile("", "syslogtest")
// f, err := ioutil.TempFile("", "syslogtest")
f, err := os.CreateTemp("", "syslogtest")
if err != nil {
log.Fatal("TempFile: ", err)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestWrite(t *testing.T) {
addr, sock, srvWG := startServer("udp", "", done)
defer srvWG.Wait()
defer sock.Close()
l, err := NewConnSyncer("udp", addr)
l, err := NewConnSyncer("udp", addr, true)
if err != nil {
t.Fatalf("NewConnSyncer() failed: %v", err)
}
Expand All @@ -166,7 +166,7 @@ func TestConcurrentWrite(t *testing.T) {
addr, sock, srvWG := startServer("udp", "", make(chan string, 1))
defer srvWG.Wait()
defer sock.Close()
s, err := NewConnSyncer("udp", addr)
s, err := NewConnSyncer("udp", addr, true)
if err != nil {
t.Fatalf("NewConnSyncer() failed: %v", err)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestConcurrentReconnect(t *testing.T) {
for i := 0; i < N; i++ {
go func() {
defer wg.Done()
s, err := NewConnSyncer("tcp", addr)
s, err := NewConnSyncer("tcp", addr, true)
if err != nil {
t.Errorf("NewConnSyncer() failed: %v", err)
return
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestFailedToConnect(t *testing.T) {
sock.Close()
srvWG.Wait()

_, err := NewConnSyncer("tcp", addr)
_, err := NewConnSyncer("tcp", addr, true)
if err == nil {
t.Fatalf("NewConnSyncer() connect to an invalid address should returns error")
}
Expand All @@ -263,7 +263,7 @@ func TestSync(t *testing.T) {
defer srvWG.Wait()
defer sock.Close()
// Should always be nil
s, err := NewConnSyncer("udp", addr)
s, err := NewConnSyncer("udp", addr, true)
if err != nil {
t.Fatalf("NewConnSyncer() failed: %v", err)
}
Expand Down

0 comments on commit 0388bf1

Please sign in to comment.