From 87e588bc2a4e7d5ed7b5f68cae07629818313c54 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Sat, 3 Apr 2021 05:37:55 +0200 Subject: [PATCH] Initial import from go-kit/kit (#1) * Initial import * GitHub Actions for CI * gofmt * Satisfy staticcheck --- .github/workflows/test.yml | 37 +++++++++++++++++++++++++++++++++++ .gitignore | 15 ++++++++++++++ LICENSE | 21 ++++++++++++++++++++ README.md | 14 ++++++++----- benchmark_test.go | 2 +- concurrency_test.go | 2 +- example_test.go | 2 +- go.mod | 8 ++++++++ go.sum | 4 ++++ json_logger_test.go | 2 +- level/benchmark_test.go | 4 ++-- level/example_test.go | 4 ++-- level/level.go | 2 +- level/level_test.go | 4 ++-- log.go | 2 +- log_test.go | 2 +- logfmt_logger_test.go | 2 +- nop_logger_test.go | 2 +- stdlib_test.go | 10 +++++----- sync_test.go | 4 ++-- syslog/example_test.go | 6 +++--- syslog/syslog.go | 4 ++-- syslog/syslog_test.go | 4 ++-- term/colorlogger.go | 2 +- term/colorlogger_test.go | 4 ++-- term/colorwriter_windows.go | 22 ++++++++++----------- term/example_test.go | 4 ++-- term/term.go | 2 +- term/terminal_windows.go | 4 ++-- term/terminal_windows_test.go | 6 ++---- value_test.go | 2 +- 31 files changed, 145 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 go.mod create mode 100644 go.sum diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7dc1486 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +on: push +name: Test +jobs: + test: + strategy: + matrix: + go-version: [1.16.x] + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + shell: bash + - name: Install golint + run: go install golang.org/x/lint/golint@latest + shell: bash + - name: Update PATH + run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH + shell: bash + - name: Checkout code + uses: actions/checkout@v1 + - name: Fmt + if: matrix.platform != 'windows-latest' # :( + run: "diff <(gofmt -d .) <(printf '')" + shell: bash + - name: Vet + run: go vet ./... + - name: Staticcheck + run: staticcheck ./... + - name: Lint + run: golint ./... + - name: Test + run: go test -race ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66fd13c --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bb5bdb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Go kit + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index a201a3d..cdafd4b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +

:warning:   PRE-RELEASE   :warning:

+

DO NOT IMPORT THIS MODULE

+

YOUR PROJECT WILL BREAK

+ # package log `package log` provides a minimal interface for structured logging in services. @@ -66,7 +70,7 @@ Redirect stdlib logger to Go kit logger. import ( "os" stdlog "log" - kitlog "github.com/go-kit/kit/log" + kitlog "github.com/go-kit/log" ) func main() { @@ -105,7 +109,7 @@ logger.Log("msg", "hello") ## Levels -Log levels are supported via the [level package](https://godoc.org/github.com/go-kit/kit/log/level). +Log levels are supported via the [level package](https://godoc.org/github.com/go-kit/log/level). ## Supported output formats @@ -136,11 +140,11 @@ Also, please see to review historical conversations about package log and the Logger interface. Value-add packages and suggestions, -like improvements to [the leveled logger](https://godoc.org/github.com/go-kit/kit/log/level), +like improvements to [the leveled logger](https://godoc.org/github.com/go-kit/log/level), are of course welcome. Good proposals should -- Be composable with [contextual loggers](https://godoc.org/github.com/go-kit/kit/log#With), -- Not break the behavior of [log.Caller](https://godoc.org/github.com/go-kit/kit/log#Caller) in any wrapped contextual loggers, and +- Be composable with [contextual loggers](https://godoc.org/github.com/go-kit/log#With), +- Not break the behavior of [log.Caller](https://godoc.org/github.com/go-kit/log#Caller) in any wrapped contextual loggers, and - Be friendly to packages that accept only an unadorned log.Logger. ## Benchmarks & comparisons diff --git a/benchmark_test.go b/benchmark_test.go index 126bfa5..785ca7c 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -3,7 +3,7 @@ package log_test import ( "testing" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) func benchmarkRunner(b *testing.B, logger log.Logger, f func(log.Logger)) { diff --git a/concurrency_test.go b/concurrency_test.go index 95a749e..91999d3 100644 --- a/concurrency_test.go +++ b/concurrency_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) // These test are designed to be run with the race detector. diff --git a/example_test.go b/example_test.go index 9766774..ec0c23c 100644 --- a/example_test.go +++ b/example_test.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) func Example_basic() { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7c87949 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/go-kit/log + +go 1.16 + +require ( + github.com/go-logfmt/logfmt v0.5.0 + github.com/go-stack/stack v1.8.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..59a7cf6 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= diff --git a/json_logger_test.go b/json_logger_test.go index 6432fc8..cb049dd 100644 --- a/json_logger_test.go +++ b/json_logger_test.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "testing" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) func TestJSONLoggerCaller(t *testing.T) { diff --git a/level/benchmark_test.go b/level/benchmark_test.go index 4fca6f0..0e50fcb 100644 --- a/level/benchmark_test.go +++ b/level/benchmark_test.go @@ -4,8 +4,8 @@ import ( "io/ioutil" "testing" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) func Benchmark(b *testing.B) { diff --git a/level/example_test.go b/level/example_test.go index fb77770..5f59f21 100644 --- a/level/example_test.go +++ b/level/example_test.go @@ -4,8 +4,8 @@ import ( "errors" "os" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) func Example_basic() { diff --git a/level/level.go b/level/level.go index c0c050f..c94756c 100644 --- a/level/level.go +++ b/level/level.go @@ -1,6 +1,6 @@ package level -import "github.com/go-kit/kit/log" +import "github.com/go-kit/log" // Error returns a logger that includes a Key/ErrorValue pair. func Error(logger log.Logger) log.Logger { diff --git a/level/level_test.go b/level/level_test.go index e362eff..035fa5d 100644 --- a/level/level_test.go +++ b/level/level_test.go @@ -7,8 +7,8 @@ import ( "strings" "testing" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) func TestVariousLevels(t *testing.T) { diff --git a/log.go b/log.go index 29b3b82..62e11ad 100644 --- a/log.go +++ b/log.go @@ -163,7 +163,7 @@ func (l *context) Log(keyvals ...interface{}) error { } kvs = append(kvs, l.sKeyvals...) if l.sHasValuer { - bindValues(kvs[len(kvs) - len(l.sKeyvals):]) + bindValues(kvs[len(kvs)-len(l.sKeyvals):]) } return l.logger.Log(kvs...) } diff --git a/log_test.go b/log_test.go index 39c4a8b..6b0cd5a 100644 --- a/log_test.go +++ b/log_test.go @@ -6,7 +6,7 @@ import ( "sync" "testing" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" "github.com/go-stack/stack" ) diff --git a/logfmt_logger_test.go b/logfmt_logger_test.go index 91bbca1..ffb66d2 100644 --- a/logfmt_logger_test.go +++ b/logfmt_logger_test.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "testing" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" "github.com/go-logfmt/logfmt" ) diff --git a/nop_logger_test.go b/nop_logger_test.go index 908ddd8..e44d492 100644 --- a/nop_logger_test.go +++ b/nop_logger_test.go @@ -3,7 +3,7 @@ package log_test import ( "testing" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) func TestNopLogger(t *testing.T) { diff --git a/stdlib_test.go b/stdlib_test.go index 2f958b7..49297cd 100644 --- a/stdlib_test.go +++ b/stdlib_test.go @@ -53,11 +53,11 @@ func TestStdLibAdapterExtraction(t *testing.T) { logger := NewLogfmtLogger(buf) writer := NewStdlibAdapter(logger) for input, want := range map[string]string{ - "hello": "msg=hello\n", - "2009/01/23: hello": "ts=2009/01/23 msg=hello\n", - "2009/01/23 01:23:23: hello": "ts=\"2009/01/23 01:23:23\" msg=hello\n", - "01:23:23: hello": "ts=01:23:23 msg=hello\n", - "2009/01/23 01:23:23.123123: hello": "ts=\"2009/01/23 01:23:23.123123\" msg=hello\n", + "hello": "msg=hello\n", + "2009/01/23: hello": "ts=2009/01/23 msg=hello\n", + "2009/01/23 01:23:23: hello": "ts=\"2009/01/23 01:23:23\" msg=hello\n", + "01:23:23: hello": "ts=01:23:23 msg=hello\n", + "2009/01/23 01:23:23.123123: hello": "ts=\"2009/01/23 01:23:23.123123\" msg=hello\n", "2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23.123123\" caller=/a/b/c/d.go:23 msg=hello\n", "01:23:23.123123 /a/b/c/d.go:23: hello": "ts=01:23:23.123123 caller=/a/b/c/d.go:23 msg=hello\n", "2009/01/23 01:23:23 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23\" caller=/a/b/c/d.go:23 msg=hello\n", diff --git a/sync_test.go b/sync_test.go index 253f256..57d6764 100644 --- a/sync_test.go +++ b/sync_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) func TestSwapLogger(t *testing.T) { @@ -58,7 +58,7 @@ func TestSwapLoggerConcurrency(t *testing.T) { } func TestSyncLoggerConcurrency(t *testing.T) { - var w io.Writer + var w io.Writer //lint:ignore S1021 I prefer this w = &bytes.Buffer{} logger := log.NewLogfmtLogger(w) logger = log.NewSyncLogger(logger) diff --git a/syslog/example_test.go b/syslog/example_test.go index 31dbf64..ed6b9e4 100644 --- a/syslog/example_test.go +++ b/syslog/example_test.go @@ -9,9 +9,9 @@ import ( gosyslog "log/syslog" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - "github.com/go-kit/kit/log/syslog" + "github.com/go-kit/log" + "github.com/go-kit/log/level" + "github.com/go-kit/log/syslog" ) func ExampleNewSyslogLogger_defaultPrioritySelector() { diff --git a/syslog/syslog.go b/syslog/syslog.go index f5b8aa1..bcb3026 100644 --- a/syslog/syslog.go +++ b/syslog/syslog.go @@ -11,8 +11,8 @@ import ( gosyslog "log/syslog" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) // SyslogWriter is an interface wrapping stdlib syslog Writer. diff --git a/syslog/syslog_test.go b/syslog/syslog_test.go index be77dfe..732401e 100644 --- a/syslog/syslog_test.go +++ b/syslog/syslog_test.go @@ -11,8 +11,8 @@ import ( gosyslog "log/syslog" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) func TestSyslogLoggerDefaultPrioritySelector(t *testing.T) { diff --git a/term/colorlogger.go b/term/colorlogger.go index 00376ce..8bfadc4 100644 --- a/term/colorlogger.go +++ b/term/colorlogger.go @@ -6,7 +6,7 @@ import ( "io" "sync" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) // Color represents an ANSI color. The zero value is Default. diff --git a/term/colorlogger_test.go b/term/colorlogger_test.go index c27ac59..eee2c74 100644 --- a/term/colorlogger_test.go +++ b/term/colorlogger_test.go @@ -8,8 +8,8 @@ import ( "sync" "testing" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/term" + "github.com/go-kit/log" + "github.com/go-kit/log/term" ) func TestColorLogger(t *testing.T) { diff --git a/term/colorwriter_windows.go b/term/colorwriter_windows.go index b27a036..b8c7250 100644 --- a/term/colorwriter_windows.go +++ b/term/colorwriter_windows.go @@ -45,7 +45,7 @@ func (w *colorWriter) Write(data []byte) (n int, err error) { er := bytes.NewBuffer(data) loop: for { - r1, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) + r1, _, _ := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) if r1 == 0 { break loop } @@ -161,22 +161,22 @@ const ( ) type ( - wchar uint16 - short int16 - dword uint32 - word uint16 + wchar uint16 //lint:ignore U1000 unused + short int16 //lint:ignore U1000 unused + dword uint32 //lint:ignore U1000 unused + word uint16 //lint:ignore U1000 unused ) type coord struct { - x short - y short + x short //lint:ignore U1000 unused + y short //lint:ignore U1000 unused } type smallRect struct { - left short - top short - right short - bottom short + left short //lint:ignore U1000 unused + top short //lint:ignore U1000 unused + right short //lint:ignore U1000 unused + bottom short //lint:ignore U1000 unused } type consoleScreenBufferInfo struct { diff --git a/term/example_test.go b/term/example_test.go index 12a3d2a..f595ead 100644 --- a/term/example_test.go +++ b/term/example_test.go @@ -4,8 +4,8 @@ import ( "errors" "os" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/term" + "github.com/go-kit/log" + "github.com/go-kit/log/term" ) func ExampleNewLogger_redErrors() { diff --git a/term/term.go b/term/term.go index 3965f1c..24dd376 100644 --- a/term/term.go +++ b/term/term.go @@ -4,7 +4,7 @@ package term import ( "io" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) // NewLogger returns a Logger that takes advantage of terminal features if diff --git a/term/terminal_windows.go b/term/terminal_windows.go index 753fd12..4b10e50 100644 --- a/term/terminal_windows.go +++ b/term/terminal_windows.go @@ -71,7 +71,7 @@ func IsMSYSTerminal(w io.Writer) bool { } // MSYS2/Cygwin terminal's name looks like: \msys-dd50a72ab4668b33-pty2-to-master - data := make([]byte, 256, 256) + data := make([]byte, 256) r, _, e := syscall.Syscall6( procGetFileInformationByHandleEx.Addr(), @@ -87,7 +87,7 @@ func IsMSYSTerminal(w io.Writer) bool { if r != 0 && e == 0 { // The first 4 bytes of the buffer are the size of the UTF16 name, in bytes. unameLen := binary.LittleEndian.Uint32(data[:4]) / 2 - uname := make([]uint16, unameLen, unameLen) + uname := make([]uint16, unameLen) for i := uint32(0); i < unameLen; i++ { uname[i] = binary.LittleEndian.Uint16(data[i*2+4 : i*2+2+4]) diff --git a/term/terminal_windows_test.go b/term/terminal_windows_test.go index 789cc28..edf768d 100644 --- a/term/terminal_windows_test.go +++ b/term/terminal_windows_test.go @@ -18,19 +18,17 @@ func (w *myWriter) Fd() uintptr { return w.fd } -var procGetStdHandle = kernel32.NewProc("GetStdHandle") +var procGetStdHandle = kernel32.NewProc("GetStdHandle") //lint:ignore U1000 unused -const stdOutputHandle = ^uintptr(0) - 11 + 1 +const stdOutputHandle = ^uintptr(0) - 11 + 1 //lint:ignore U1000 unused func getConsoleHandle() syscall.Handle { ptr, err := syscall.UTF16PtrFromString("CONOUT$") - if err != nil { panic(err) } handle, err := syscall.CreateFile(ptr, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, nil, syscall.OPEN_EXISTING, 0, 0) - if err != nil { panic(err) } diff --git a/value_test.go b/value_test.go index 3a0c835..bfec9d2 100644 --- a/value_test.go +++ b/value_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" ) func TestValueBinding(t *testing.T) {