Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Oct 3, 2023
0 parents commit 1a8d41d
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [samber]
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint

on:
push:
tags:
branches:
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@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
working-directory: ./

# Optional: golangci-lint command line arguments.
args: --timeout 60s --max-same-issues 50

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# optionally use a specific version of Go rather than the latest one
go_version: '1.21'
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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

# 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 }}
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
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
38 changes: 38 additions & 0 deletions .gitignore
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/
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) 2023 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.
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

BIN=go

build:
${BIN} 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:
${BIN} test -v -coverprofile=cover.out -covermode=atomic .
${BIN} tool cover -html=cover.out -o cover.html

tools:
${BIN} install github.com/cespare/reflex@latest
${BIN} install github.com/rakyll/gotest@latest
${BIN} install github.com/psampaz/go-mod-outdated@latest
${BIN} install github.com/jondot/goweight@latest
${BIN} install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
${BIN} get -t -u golang.org/x/tools/cmd/cover
${BIN} 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:
${BIN} list -json -m all | nancy sleuth

outdated:
${BIN} list -u -m -json all | go-mod-outdated -update -direct

weight:
goweight
107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

# slog toolchain

[![tag](https://img.shields.io/github/tag/samber/slog-common.svg)](https://github.com/samber/slog-common/releases)
![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)
[![GoDoc](https://godoc.org/github.com/samber/slog-common?status.svg)](https://pkg.go.dev/github.com/samber/slog-common)
![Build Status](https://github.com/samber/slog-common/actions/workflows/test.yml/badge.svg)
[![Go report](https://goreportcard.com/badge/github.com/samber/slog-common)](https://goreportcard.com/report/github.com/samber/slog-common)
[![Coverage](https://img.shields.io/codecov/c/github/samber/slog-common)](https://codecov.io/gh/samber/slog-common)
[![Contributors](https://img.shields.io/github/contributors/samber/slog-common)](https://github.com/samber/slog-common/graphs/contributors)
[![License](https://img.shields.io/github/license/samber/slog-common)](./LICENSE)

A toolchain 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-datadog](https://github.com/samber/slog-datadog): A `slog` handler for `Datadog`
- [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-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`

## 🚀 Install

```sh
go get github.com/samber/slog-common
```

**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-common](https://pkg.go.dev/github.com/samber/slog-common)

```go
m := AttrsToValue(slog.Bool("foo", true), slog.String("bar", "baz"))
// {"foo": true, "bar": "baz"}

k, v := AttrToValue(slog.Bool("foo", true))
// "foo", true

v := AnyValueToString(slog.IntValue(42))
// "42"

err := fmt.Errorf("an error")

m := FormatErrorKey(map[string]any{"foo": "bar", "msg": err}, "msg")
// {"foo": "bar", "msg": {"kind": "*errorString", "error": "an error", "stack": nil}}

m := FormatError(err)
// {"kind": "*errorString", "error": "an error", "stack": nil}
```

## 🤝 Contributing

- Ping me on twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))
- Fork the [project](https://github.com/samber/slog-common)
- Fix [open issues](https://github.com/samber/slog-common/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-common)

## 💫 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.
Loading

0 comments on commit 1a8d41d

Please sign in to comment.