-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 33393d2
Showing
15 changed files
with
616 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github: [samber] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
stable: false | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
args: --timeout 120s --max-same-issues 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
semver: | ||
type: string | ||
description: 'Semver (eg: v1.2.3)' | ||
required: true | ||
|
||
jobs: | ||
release: | ||
if: github.triggering_actor == 'samber' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
stable: false | ||
|
||
- name: Test | ||
run: make test | ||
|
||
# remove tests in order to clean dependencies | ||
- name: Remove xxx_test.go files | ||
run: rm -rf *_test.go ./examples ./images | ||
|
||
- name: Set library version in version.go | ||
run: sed -i 's/VERSION/${{ inputs.semver }}/g' version.go | ||
|
||
# cleanup test dependencies | ||
- name: Cleanup dependencies | ||
run: go mod tidy | ||
|
||
- name: List files | ||
run: tree -Cfi | ||
- name: Write new go.mod into logs | ||
run: cat go.mod | ||
- name: Write new go.sum into logs | ||
run: cat go.sum | ||
|
||
- name: Create tag | ||
run: | | ||
git config --global user.name '${{ github.triggering_actor }}' | ||
git config --global user.email "${{ github.triggering_actor}}@users.noreply.github.com" | ||
git add . | ||
git commit --allow-empty -m 'bump ${{ inputs.semver }}' | ||
git tag ${{ inputs.semver }} | ||
git push origin ${{ inputs.semver }} | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
name: ${{ inputs.semver }} | ||
tag_name: ${{ inputs.semver }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
tags: | ||
branches: | ||
pull_request: | ||
|
||
jobs: | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
stable: false | ||
|
||
- name: Build | ||
run: make build | ||
|
||
- name: Test | ||
run: make test | ||
|
||
- name: Test | ||
run: make coverage | ||
|
||
- name: Codecov | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: ./cover.out | ||
flags: unittests | ||
verbose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
# Created by https://www.toptal.com/developers/gitignore/api/go | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=go | ||
|
||
### Go ### | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# 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/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
### Go Patch ### | ||
/vendor/ | ||
/Godeps/ | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/go | ||
|
||
cover.out | ||
cover.html | ||
.vscode | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Samuel Berthe | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
build: | ||
go build -v ./... | ||
|
||
test: | ||
go test -race -v ./... | ||
watch-test: | ||
reflex -t 50ms -s -- sh -c 'gotest -race -v ./...' | ||
|
||
bench: | ||
go test -benchmem -count 3 -bench ./... | ||
watch-bench: | ||
reflex -t 50ms -s -- sh -c 'go test -benchmem -count 3 -bench ./...' | ||
|
||
coverage: | ||
go test -v -coverprofile=cover.out -covermode=atomic ./... | ||
go tool cover -html=cover.out -o cover.html | ||
|
||
tools: | ||
go install github.com/cespare/reflex@latest | ||
go install github.com/rakyll/gotest@latest | ||
go install github.com/psampaz/go-mod-outdated@latest | ||
go install github.com/jondot/goweight@latest | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
go get -t -u golang.org/x/tools/cmd/cover | ||
go install github.com/sonatype-nexus-community/nancy@latest | ||
go mod tidy | ||
|
||
lint: | ||
golangci-lint run --timeout 60s --max-same-issues 50 ./... | ||
lint-fix: | ||
golangci-lint run --timeout 60s --max-same-issues 50 --fix ./... | ||
|
||
audit: | ||
go list -json -m all | nancy sleuth | ||
|
||
outdated: | ||
go list -u -m -json all | go-mod-outdated -update -direct | ||
|
||
weight: | ||
goweight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
|
||
# slog: Betterstack handler | ||
|
||
[![tag](https://img.shields.io/github/tag/samber/slog-betterstack.svg)](https://github.com/samber/slog-betterstack/releases) | ||
![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c) | ||
[![GoDoc](https://godoc.org/github.com/samber/slog-betterstack?status.svg)](https://pkg.go.dev/github.com/samber/slog-betterstack) | ||
![Build Status](https://github.com/samber/slog-betterstack/actions/workflows/test.yml/badge.svg) | ||
[![Go report](https://goreportcard.com/badge/github.com/samber/slog-betterstack)](https://goreportcard.com/report/github.com/samber/slog-betterstack) | ||
[![Coverage](https://img.shields.io/codecov/c/github/samber/slog-betterstack)](https://codecov.io/gh/samber/slog-betterstack) | ||
[![Contributors](https://img.shields.io/github/contributors/samber/slog-betterstack)](https://github.com/samber/slog-betterstack/graphs/contributors) | ||
[![License](https://img.shields.io/github/license/samber/slog-betterstack)](./LICENSE) | ||
|
||
A [Betterstack](https://betterstack.com) Handler for [slog](https://pkg.go.dev/log/slog) Go library. | ||
|
||
**See also:** | ||
|
||
- [slog-multi](https://github.com/samber/slog-multi): `slog.Handler` chaining, fanout, routing, failover, load balancing... | ||
- [slog-formatter](https://github.com/samber/slog-formatter): `slog` attribute formatting | ||
- [slog-sampling](https://github.com/samber/slog-sampling): `slog` sampling policy | ||
- [slog-gin](https://github.com/samber/slog-gin): Gin middleware for `slog` logger | ||
- [slog-echo](https://github.com/samber/slog-echo): Echo middleware for `slog` logger | ||
- [slog-fiber](https://github.com/samber/slog-fiber): Fiber middleware for `slog` logger | ||
- [slog-chi](https://github.com/samber/slog-chi): Chi middleware for `slog` logger | ||
- [slog-http](https://github.com/samber/slog-http): `net/http` middleware for `slog` logger | ||
- [slog-datadog](https://github.com/samber/slog-datadog): A `slog` handler for `Datadog` | ||
- [slog-betterstack](https://github.com/samber/slog-betterstack): A `slog` handler for `Betterstack` | ||
- [slog-rollbar](https://github.com/samber/slog-rollbar): A `slog` handler for `Rollbar` | ||
- [slog-sentry](https://github.com/samber/slog-sentry): A `slog` handler for `Sentry` | ||
- [slog-syslog](https://github.com/samber/slog-syslog): A `slog` handler for `Syslog` | ||
- [slog-logstash](https://github.com/samber/slog-logstash): A `slog` handler for `Logstash` | ||
- [slog-fluentd](https://github.com/samber/slog-fluentd): A `slog` handler for `Fluentd` | ||
- [slog-graylog](https://github.com/samber/slog-graylog): A `slog` handler for `Graylog` | ||
- [slog-loki](https://github.com/samber/slog-loki): A `slog` handler for `Loki` | ||
- [slog-slack](https://github.com/samber/slog-slack): A `slog` handler for `Slack` | ||
- [slog-telegram](https://github.com/samber/slog-telegram): A `slog` handler for `Telegram` | ||
- [slog-mattermost](https://github.com/samber/slog-mattermost): A `slog` handler for `Mattermost` | ||
- [slog-microsoft-teams](https://github.com/samber/slog-microsoft-teams): A `slog` handler for `Microsoft Teams` | ||
- [slog-webhook](https://github.com/samber/slog-webhook): A `slog` handler for `Webhook` | ||
- [slog-kafka](https://github.com/samber/slog-kafka): A `slog` handler for `Kafka` | ||
- [slog-nats](https://github.com/samber/slog-nats): A `slog` handler for `NATS` | ||
- [slog-parquet](https://github.com/samber/slog-parquet): A `slog` handler for `Parquet` + `Object Storage` | ||
- [slog-zap](https://github.com/samber/slog-zap): A `slog` handler for `Zap` | ||
- [slog-zerolog](https://github.com/samber/slog-zerolog): A `slog` handler for `Zerolog` | ||
- [slog-logrus](https://github.com/samber/slog-logrus): A `slog` handler for `Logrus` | ||
- [slog-channel](https://github.com/samber/slog-channel): A `slog` handler for Go channels | ||
|
||
## 🚀 Install | ||
|
||
```sh | ||
go get github.com/samber/slog-betterstack | ||
``` | ||
|
||
**Compatibility**: go >= 1.21 | ||
|
||
No breaking changes will be made to exported APIs before v2.0.0. | ||
|
||
## 💡 Usage | ||
|
||
GoDoc: [https://pkg.go.dev/github.com/samber/slog-betterstack](https://pkg.go.dev/github.com/samber/slog-betterstack) | ||
|
||
### Handler options | ||
|
||
```go | ||
type Option struct { | ||
// log level (default: debug) | ||
Level slog.Leveler | ||
|
||
// token | ||
Token string | ||
Timeout time.Duration // default: 10s | ||
|
||
// optional: customize record builder | ||
Converter Converter | ||
// optional: custom marshaler | ||
Marshaler func(v any) ([]byte, error) | ||
|
||
// optional: see slog.HandlerOptions | ||
AddSource bool | ||
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr | ||
} | ||
``` | ||
|
||
Other global parameters: | ||
|
||
```go | ||
slogbetterstack.SourceKey = "runtime" | ||
slogbetterstack.ContextKey = "context" | ||
slogbetterstack.ErrorKeys = []string{"error", "err"} | ||
``` | ||
|
||
### Example | ||
|
||
```go | ||
import ( | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
slogbetterstack "github.com/samber/slog-betterstack" | ||
|
||
"log/slog" | ||
) | ||
|
||
func main() { | ||
logger := slog.New(slogbetterstack.Option{Level: slog.LevelDebug, Token: "xxxxx"}.NewBetterstackHandler()) | ||
logger = logger.With("release", "v1.0.0") | ||
|
||
logger. | ||
With( | ||
slog.Group("user", | ||
slog.String("id", "user-123"), | ||
slog.Time("created_at", time.Now()), | ||
), | ||
). | ||
With("error", fmt.Errorf("an error")). | ||
Error("a message", slog.Int("count", 1)) | ||
} | ||
``` | ||
|
||
## 🤝 Contributing | ||
|
||
- Ping me on Twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :)) | ||
- Fork the [project](https://github.com/samber/slog-betterstack) | ||
- Fix [open issues](https://github.com/samber/slog-betterstack/issues) or request new features | ||
|
||
Don't hesitate ;) | ||
|
||
```bash | ||
# Install some dev dependencies | ||
make tools | ||
|
||
# Run tests | ||
make test | ||
# or | ||
make watch-test | ||
``` | ||
|
||
## 👤 Contributors | ||
|
||
![Contributors](https://contrib.rocks/image?repo=samber/slog-betterstack) | ||
|
||
## 💫 Show your support | ||
|
||
Give a ⭐️ if this project helped you! | ||
|
||
[![GitHub Sponsors](https://img.shields.io/github/sponsors/samber?style=for-the-badge)](https://github.com/sponsors/samber) | ||
|
||
## 📝 License | ||
|
||
Copyright © 2023 [Samuel Berthe](https://github.com/samber). | ||
|
||
This project is [MIT](./LICENSE) licensed. |
Oops, something went wrong.