Skip to content

Commit

Permalink
feat: add slog adapter (#1)
Browse files Browse the repository at this point in the history
* feat: add slog adapter

* ci: upgrade pre commit hooks

* fix: modify mod versions

* chore: save

* ci: modify pipelines

* chore: modify go version

* ci: remove go 1.20 from pipeline

* ci: complete first iteration of tagging
  • Loading branch information
danteay committed Apr 17, 2024
1 parent 0df47fa commit 44f2c85
Show file tree
Hide file tree
Showing 37 changed files with 889 additions and 303 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
32 changes: 32 additions & 0 deletions .github/workflows/cleanuo_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Cleanup caches by a branch

on:
pull_request:
types:
- closed

jobs:
cleanup:
name: Cleanup
runs-on: ubuntu-latest
steps:
- name: Cleanup all caches for repo
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62 changes: 62 additions & 0 deletions .github/workflows/tag_adapters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Tag adapters

on:
push:
branches:
- main

jobs:
tag_adapter:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
name: Tag adapter
runs-on: ubuntu-latest
strategy:
matrix:
adapter:
- slog
- zerolog
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.ACCESS_TOKEN }}"
ref: "main"

- name: Files modified
id: check
uses: tj-actions/[email protected]
with:
files: |
./adapters/${{ matrix.adapter }}/**
- name: Should skip
if: steps.check.outputs.any_changed != 'true'
run: exit 78

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install commitizen
run: pip install -U commitizen

- id: cz
name: Create bump and changelog
working-directory: adapters/${{ matrix.adapter }}
run: |
python -m pip install -U commitizen
cz bump --changelog --yes
export REV=`cz version --project`
echo "version=$REV" >> $GITHUB_OUTPUT
- name: Push changes
uses: Woile/github-push-action@master
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
tags: "true"
branch: "main"

- name: Print Version
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"
60 changes: 60 additions & 0 deletions .github/workflows/tag_logger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Tag Logger

on:
push:
branches:
- main

jobs:
tag_adapter:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
name: Tag logger
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.ACCESS_TOKEN }}"
ref: "main"

- name: Files modified
id: check
uses: tj-actions/[email protected]
with:
files: |
./internal/**
./*.go
./go.mod
./go.sum
- name: Should skip
if: steps.check.outputs.any_changed != 'true'
run: exit 78

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install commitizen
run: pip install -U commitizen

- id: cz
name: Create bump and changelog
working-directory: ${{ matrix.module }}
run: |
python -m pip install -U commitizen
cz bump --changelog --yes
export REV=`cz version --project`
echo "version=$REV" >> $GITHUB_OUTPUT
- name: Push changes
uses: Woile/github-push-action@master
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
tags: "true"
branch: "main"

- name: Print Version
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"
62 changes: 62 additions & 0 deletions .github/workflows/tag_modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Tag modules

on:
push:
branches:
- main

jobs:
tag_adapter:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
name: Tag modules
runs-on: ubuntu-latest
strategy:
matrix:
module:
- fields
- levels
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.ACCESS_TOKEN }}"
ref: "main"

- name: Files modified
id: check
uses: tj-actions/[email protected]
with:
files: |
./${{ matrix.module }}/**
- name: Should skip
if: steps.check.outputs.any_changed != 'true'
run: exit 78

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install commitizen
run: pip install -U commitizen

- id: cz
name: Create bump and changelog
working-directory: ${{ matrix.module }}
run: |
python -m pip install -U commitizen
cz bump --changelog --yes
export REV=`cz version --project`
echo "version=$REV" >> $GITHUB_OUTPUT
- name: Push changes
uses: Woile/github-push-action@master
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
tags: "true"
branch: "main"

- name: Print Version
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"
35 changes: 35 additions & 0 deletions .github/workflows/test_adapters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test adapters

on:
pull_request:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
adapter:
- slog
- zerolog
go-version:
- 1.21.x
- 1.22.x
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: ${{ matrix.go-version }}

- name: Install dependencies
working-directory: adapters/${{ matrix.adapter }}
run: go mod download

- name: Run tests
working-directory: adapters/${{ matrix.adapter }}
run: go test -v github.com/danteay/golog/adapters/${{ matrix.adapter }}
30 changes: 30 additions & 0 deletions .github/workflows/test_logger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test logger

on:
pull_request:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.21.x
- 1.22.x
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: ${{ matrix.go-version }}

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test -v ./...
35 changes: 35 additions & 0 deletions .github/workflows/test_modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test modules

on:
pull_request:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
module:
- fields
- levels
go-version:
- 1.21.x
- 1.22.x
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: ${{ matrix.go-version }}

- name: Install dependencies
working-directory: ${{ matrix.module }}
run: go mod download

- name: Run tests
working-directory: ${{ matrix.module }}
run: go test -v github.com/danteay/golog/${{ matrix.module }}
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work
go.work.sum

# Editor configs
.idea/
.vscode/

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ repos:
args: [ "-config=revive.toml", "-formatter=friendly" ]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/commitizen-tools/commitizen
rev: 3.10.0
rev: v3.22.0
hooks:
- id: commitizen
stages: [commit-msg]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Syntactic sugar for logging and some other cool stuff.

Implements the Adapter pattern to replace the underlying logger. By default, it uses [zerolog][1], but you can create
Implements the Adapter pattern to replace the underlying logger. By default, it uses [slog][1], but you can create
any other logger implementation by implementing the next interface:

```go
Expand All @@ -20,7 +20,7 @@ type Adapter interface {

## Requirements

- Go 1.19+
- Go 1.22+

## Install

Expand Down Expand Up @@ -230,4 +230,4 @@ the beginning of the execution and flush them at the end of the execution.
If you use context fields with a custom store, you should flush them manually when you don't need them anymore, or
when the current execution scope ends.

[1]: https://github.com/rs/zerolog
[1]: https://betterstack.com/community/guides/logging/logging-in-go/
Loading

0 comments on commit 44f2c85

Please sign in to comment.