Skip to content

Commit

Permalink
version 0.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Apr 24, 2024
1 parent cc1dbac commit f011779
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
go_version: [1.21.x]
go_version: [1.22.x]
steps:

- name: Check out code into the Go module directory
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Wed 24 April 2024 | v0.1.12

Accept `slog.Attr` among with `golog.Fields` for extra log data.

## Wed 11 November 2023 | v0.1.11

- Add integration for `"log/slog"` package:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Or edit your project's go.mod file and execute $ go build.
```mod
module your_project_name
go 1.21
go 1.22
require (
github.com/kataras/golog v0.1.11
Expand Down
6 changes: 3 additions & 3 deletions _examples/ngrok-logger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ replace github.com/kataras/golog => ../../
require (
github.com/kataras/golog v0.0.0-00010101000000-000000000000
golang.ngrok.com/ngrok v1.7.0
xorm.io/xorm v1.3.6
)

require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/inconshreveable/log15 v3.0.0-testing.3+incompatible // indirect
github.com/inconshreveable/log15/v3 v3.0.0-testing.5 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
Expand All @@ -20,9 +20,9 @@ require (
github.com/mattn/go-isatty v0.0.16 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.ngrok.com/muxado/v2 v2.0.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/term v0.16.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
280 changes: 6 additions & 274 deletions _examples/ngrok-logger/go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Source code and other details for the project are available at GitHub:
# Current Version
0.1.11
0.1.12
# Installation
Expand Down Expand Up @@ -371,4 +371,4 @@ Examples:
package golog

// Version is the version string representation of the "golog" package.
const Version = "0.1.11"
const Version = "0.1.12"
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/kataras/golog

go 1.21
go 1.22

require github.com/kataras/pio v0.0.13

require golang.org/x/sys v0.16.0 // indirect
require golang.org/x/sys v0.13.0 // indirect
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/kataras/pio v0.0.13 h1:x0rXVX0fviDTXOOLOmr4MUxOabu1InVSTu5itF8CXCM=
github.com/kataras/pio v0.0.13/go.mod h1:k3HNuSw+eJ8Pm2lA4lRhg3DiCjVgHlP8hmXApSej3oM=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26 changes: 22 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package golog
import (
"fmt"
"io"
"log/slog"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -371,26 +372,43 @@ func (l *Logger) Println(v ...interface{}) {
l.print(DisableLevel, fmt.Sprint(v...), true, nil)
}

// splitArgsFields splits the given values to arguments and fields.
// It returns the arguments and the fields.
// It's used to separate the arguments from the fields
// when a `Fields` or `[]slog.Attr` is passed as a value.
func splitArgsFields(values []interface{}) ([]interface{}, Fields) {
var (
args = values[:0]
fields Fields
)

for _, value := range values {
if f, ok := value.(Fields); ok {
switch f := value.(type) {
case Fields:
if fields == nil {
fields = make(Fields)
}

for k, v := range f {
fields[k] = v
}
case []slog.Attr:
if fields == nil {
fields = make(Fields)
}

continue
}
for _, attr := range f {
fields[attr.Key] = attr.Value.Any()
}
case slog.Attr: // a single slog attr.
if fields == nil {
fields = make(Fields)
}

args = append(args, value) // use it as fmt argument.
fields[f.Key] = f.Value.Any()
default:
args = append(args, value) // use it as fmt argument.
}
}

return args, fields
Expand Down

0 comments on commit f011779

Please sign in to comment.