Compare commits
No commits in common. "main" and "v0.4.0" have entirely different histories.
11 changed files with 9 additions and 268 deletions
|
@ -1,81 +0,0 @@
|
||||||
name: Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- beta
|
|
||||||
- develop
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
checks:
|
|
||||||
name: Checks
|
|
||||||
runs-on: docker
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.23.x'
|
|
||||||
check-latest: true
|
|
||||||
- name: Run go fmt and go vet
|
|
||||||
run: |
|
|
||||||
go fmt $(go list ./...)
|
|
||||||
go vet $(go list ./...)
|
|
||||||
|
|
||||||
code-coverage:
|
|
||||||
name: Code Coverage
|
|
||||||
runs-on: docker
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.23.x'
|
|
||||||
check-latest: true
|
|
||||||
- name: Run tests and generate coverage report
|
|
||||||
run: |
|
|
||||||
go test -covermode=count -coverprofile coverage.cov $(go list ./...)
|
|
||||||
go tool cover -func=coverage.cov
|
|
||||||
go tool cover -html=coverage.cov -o coverage.html
|
|
||||||
- name: Upload coverage artifacts
|
|
||||||
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: coverage-reports
|
|
||||||
path: |
|
|
||||||
coverage.cov
|
|
||||||
coverage.html
|
|
||||||
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
runs-on: docker
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
go:
|
|
||||||
- GOOS: darwin
|
|
||||||
GOARCH: amd64
|
|
||||||
- GOOS: darwin
|
|
||||||
GOARCH: arm64
|
|
||||||
- GOOS: linux
|
|
||||||
GOARCH: amd64
|
|
||||||
- GOOS: linux
|
|
||||||
GOARCH: arm64
|
|
||||||
- GOOS: windows
|
|
||||||
GOARCH: amd64
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.23.x'
|
|
||||||
check-latest: true
|
|
||||||
- name: Set environment variables
|
|
||||||
run: |
|
|
||||||
echo "GOOS=${{ matrix.go.GOOS }}" >> $GITHUB_ENV
|
|
||||||
echo "GOARCH=${{ matrix.go.GOARCH }}" >> $GITHUB_ENV
|
|
||||||
- name: Build
|
|
||||||
run: go build .
|
|
|
@ -1,20 +0,0 @@
|
||||||
name: Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- beta
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
name: Semantic Release
|
|
||||||
runs-on: docker
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Semantic Release
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
npm install -g semantic-release@23 conventional-changelog-conventionalcommits@7
|
|
||||||
semantic-release
|
|
72
.releaserc
72
.releaserc
|
@ -1,72 +0,0 @@
|
||||||
{
|
|
||||||
"branches": [
|
|
||||||
"main",
|
|
||||||
{
|
|
||||||
"name": "beta",
|
|
||||||
"prerelease": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
[
|
|
||||||
"@semantic-release/commit-analyzer",
|
|
||||||
{
|
|
||||||
"preset": "conventionalcommits",
|
|
||||||
"releaseRules": [
|
|
||||||
{
|
|
||||||
"type": "chore",
|
|
||||||
"release": "patch"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "build",
|
|
||||||
"release": "patch"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "ci",
|
|
||||||
"release": "patch"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@semantic-release/release-notes-generator",
|
|
||||||
{
|
|
||||||
"preset": "conventionalcommits",
|
|
||||||
"presetConfig": {
|
|
||||||
"types": [
|
|
||||||
{
|
|
||||||
"type": "feat",
|
|
||||||
"section": "Features"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "feature",
|
|
||||||
"section": "Features"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "fix",
|
|
||||||
"section": "Bug Fixes"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "perf",
|
|
||||||
"section": "Performance Improvements"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "revert",
|
|
||||||
"section": "Reverts"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "chore",
|
|
||||||
"section": "Miscellaneous Chores"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@semantic-release/github",
|
|
||||||
{
|
|
||||||
"successCommentCondition": false,
|
|
||||||
"failTitle": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -12,8 +12,6 @@ func main(){
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Check out this [simple example file](cmd/simple/main.go) for the basic usage.
|
|
||||||
|
|
||||||
## Multiple Log Instance
|
## Multiple Log Instance
|
||||||
|
|
||||||
Create a new log instance (instead of using the `Default`).
|
Create a new log instance (instead of using the `Default`).
|
||||||
|
@ -43,6 +41,7 @@ var myLog := log.NewLogger(
|
||||||
[]*Output{output1, output2}
|
[]*Output{output1, output2}
|
||||||
)
|
)
|
||||||
myLog.Info("My First Info Message")
|
myLog.Info("My First Info Message")
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Custom Formatter / Printer
|
## Custom Formatter / Printer
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.martin-riedl.de/golang/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
advancedSettings()
|
|
||||||
}
|
|
||||||
|
|
||||||
func advancedSettings() {
|
|
||||||
// Key Value Formatter with special settings
|
|
||||||
formatter := log.NewFormatterKeyValue()
|
|
||||||
formatter.HighPriorityKeys = []string{"firstField"}
|
|
||||||
formatter.PriorityKeys = []string{"secondField"}
|
|
||||||
formatter.TimeFormat = time.RFC3339Nano
|
|
||||||
|
|
||||||
// create new log instance
|
|
||||||
output := log.NewOutput(log.LevelDebug, formatter, log.NewPrinterStdout())
|
|
||||||
logger := log.NewLogger([]*log.Output{output})
|
|
||||||
|
|
||||||
// log some message
|
|
||||||
logger.WithMap(log.Map{
|
|
||||||
"someField": "Martin",
|
|
||||||
"firstField": "John",
|
|
||||||
"secondField": "Doe",
|
|
||||||
}).Info("This is an info message")
|
|
||||||
}
|
|
|
@ -1,24 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"git.martin-riedl.de/golang/log"
|
"git.martin-riedl.de/golang/log"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
someMethod()
|
someMethod()
|
||||||
anotherMethod()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func someMethod() {
|
func someMethod() {
|
||||||
log.Default.Info("Hello World")
|
log.Default.Info("Hello World")
|
||||||
log.Default.With("os", runtime.GOOS).Warning("environment detected")
|
log.Default.With("os", runtime.GOOS).Info("environment detected")
|
||||||
}
|
|
||||||
|
|
||||||
func anotherMethod() {
|
|
||||||
log.Default.WithMap(log.Map{
|
|
||||||
"foo": "bar",
|
|
||||||
"bar": "baz",
|
|
||||||
}).Info("Second Hello World")
|
|
||||||
}
|
}
|
||||||
|
|
9
entry.go
9
entry.go
|
@ -34,8 +34,6 @@ type Content struct {
|
||||||
Value any `json:"value"`
|
Value any `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Map map[string]any
|
|
||||||
|
|
||||||
func NewEntry(logger *Logger) *Entry {
|
func NewEntry(logger *Logger) *Entry {
|
||||||
return &Entry{
|
return &Entry{
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
|
@ -51,13 +49,6 @@ func (entry *Entry) With(key string, value any) *Entry {
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) WithMap(entries Map) *Entry {
|
|
||||||
for key, value := range entries {
|
|
||||||
entry.With(key, value)
|
|
||||||
}
|
|
||||||
return entry
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) WithContent(content []Content) *Entry {
|
func (entry *Entry) WithContent(content []Content) *Entry {
|
||||||
entry.Content = append(entry.Content, content...)
|
entry.Content = append(entry.Content, content...)
|
||||||
return entry
|
return entry
|
||||||
|
|
|
@ -24,7 +24,7 @@ import (
|
||||||
type FormatterJSON struct {
|
type FormatterJSON struct {
|
||||||
FlatContent bool
|
FlatContent bool
|
||||||
TimeFormat string
|
TimeFormat string
|
||||||
data map[string]any
|
data map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFormatterJSON() *FormatterJSON {
|
func NewFormatterJSON() *FormatterJSON {
|
||||||
|
@ -35,7 +35,7 @@ func NewFormatterJSON() *FormatterJSON {
|
||||||
|
|
||||||
func (formatter *FormatterJSON) Begin(entry *Entry) {
|
func (formatter *FormatterJSON) Begin(entry *Entry) {
|
||||||
// reset formatter
|
// reset formatter
|
||||||
formatter.data = make(map[string]any)
|
formatter.data = make(map[string]interface{})
|
||||||
|
|
||||||
// add timestamp
|
// add timestamp
|
||||||
formatter.data["time"] = entry.Time.Format(formatter.TimeFormat)
|
formatter.data["time"] = entry.Time.Format(formatter.TimeFormat)
|
||||||
|
@ -65,7 +65,7 @@ func (formatter *FormatterJSON) Process(entry *Entry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (formatter *FormatterJSON) End(_ *Entry) []byte {
|
func (formatter *FormatterJSON) End(entry *Entry) []byte {
|
||||||
// build JSON
|
// build JSON
|
||||||
data, err := json.Marshal(formatter.data)
|
data, err := json.Marshal(formatter.data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,17 +16,12 @@ package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FormatterKeyValue struct {
|
type FormatterKeyValue struct {
|
||||||
TimeFormat string
|
TimeFormat string
|
||||||
// HighPriorityKeys are printed before the actual log message
|
|
||||||
HighPriorityKeys []string
|
|
||||||
// PriorityKeys are printed after the log message
|
|
||||||
PriorityKeys []string
|
|
||||||
builder strings.Builder
|
builder strings.Builder
|
||||||
isFirstKVWritten bool
|
isFirstKVWritten bool
|
||||||
}
|
}
|
||||||
|
@ -50,23 +45,9 @@ func (formatter *FormatterKeyValue) Begin(entry *Entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (formatter *FormatterKeyValue) Process(entry *Entry) {
|
func (formatter *FormatterKeyValue) Process(entry *Entry) {
|
||||||
// log high priority keys
|
|
||||||
for _, content := range entry.Content {
|
|
||||||
if slices.Contains(formatter.HighPriorityKeys, content.Key) {
|
|
||||||
formatter.addKV(content.Key, content.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add message
|
// add message
|
||||||
formatter.addKV("message", entry.Message)
|
formatter.addKV("message", entry.Message)
|
||||||
|
|
||||||
// log priority keys
|
|
||||||
for _, content := range entry.Content {
|
|
||||||
if slices.Contains(formatter.PriorityKeys, content.Key) {
|
|
||||||
formatter.addKV(content.Key, content.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add call stack
|
// add call stack
|
||||||
if len(entry.CallStack) > 0 {
|
if len(entry.CallStack) > 0 {
|
||||||
caller := entry.CallStack[0]
|
caller := entry.CallStack[0]
|
||||||
|
@ -76,10 +57,7 @@ func (formatter *FormatterKeyValue) Process(entry *Entry) {
|
||||||
|
|
||||||
// add additional fields
|
// add additional fields
|
||||||
for _, content := range entry.Content {
|
for _, content := range entry.Content {
|
||||||
if !slices.Contains(formatter.HighPriorityKeys, content.Key) &&
|
formatter.addKV(content.Key, content.Value)
|
||||||
!slices.Contains(formatter.PriorityKeys, content.Key) {
|
|
||||||
formatter.addKV(content.Key, content.Value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +82,7 @@ func (formatter *FormatterKeyValue) addKV(key string, value any) {
|
||||||
formatter.builder.WriteString(val)
|
formatter.builder.WriteString(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (formatter *FormatterKeyValue) End(_ *Entry) []byte {
|
func (formatter *FormatterKeyValue) End(entry *Entry) []byte {
|
||||||
// send data
|
// send data
|
||||||
return []byte(formatter.builder.String())
|
return []byte(formatter.builder.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,12 +113,6 @@ func (logger *Logger) With(key string, value any) *Entry {
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *Logger) WithMap(entries Map) *Entry {
|
|
||||||
entry := NewEntry(logger)
|
|
||||||
entry.WithMap(entries)
|
|
||||||
return entry
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger *Logger) WithContent(content []Content) *Entry {
|
func (logger *Logger) WithContent(content []Content) *Entry {
|
||||||
entry := NewEntry(logger)
|
entry := NewEntry(logger)
|
||||||
entry.WithContent(content)
|
entry.WithContent(content)
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": [
|
|
||||||
"local>ci/renovate//configs/base"
|
|
||||||
],
|
|
||||||
"baseBranches": [
|
|
||||||
"develop"
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue