Skip to content

Commit

Permalink
Initial import from go-kit/kit (#1)
Browse files Browse the repository at this point in the history
* Initial import

* GitHub Actions for CI

* gofmt

* Satisfy staticcheck
  • Loading branch information
peterbourgon authored and ChrisHines committed May 11, 2021
1 parent 5e1beb4 commit 87e588b
Show file tree
Hide file tree
Showing 31 changed files with 145 additions and 58 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<h3 align="center">:warning: &nbsp; PRE-RELEASE &nbsp; :warning:</h3>
<h4 align="center">DO NOT IMPORT THIS MODULE</h4>
<h4 align="center">YOUR PROJECT WILL BREAK</h4>

# package log

`package log` provides a minimal interface for structured logging in services.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/go-kit/kit/log"
"github.com/go-kit/log"
)

func Example_basic() {
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion json_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io/ioutil"
"testing"

"github.com/go-kit/kit/log"
"github.com/go-kit/log"
)

func TestJSONLoggerCaller(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions level/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions level/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion level/level.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions level/level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
2 changes: 1 addition & 1 deletion log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"testing"

"github.com/go-kit/kit/log"
"github.com/go-kit/log"
"github.com/go-stack/stack"
)

Expand Down
2 changes: 1 addition & 1 deletion logfmt_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io/ioutil"
"testing"

"github.com/go-kit/kit/log"
"github.com/go-kit/log"
"github.com/go-logfmt/logfmt"
)

Expand Down
2 changes: 1 addition & 1 deletion nop_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/go-kit/kit/log"
"github.com/go-kit/log"
)

func TestSwapLogger(t *testing.T) {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions syslog/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions syslog/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion term/colorlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions term/colorlogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 11 additions & 11 deletions term/colorwriter_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions term/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion term/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 87e588b

Please sign in to comment.