mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-06 08:39:09 +02:00
Bugfix/logging (#346)
* Fixed inability to pass custom ID to th runtime logger * Removed UUID module * Removed redundant check
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
### 0.8.2
|
### 0.8.2
|
||||||
#### Fixed
|
#### Fixed
|
||||||
- Scrolling position is not centered.
|
- Scrolling position is not centered.
|
||||||
|
- Unable to set custom logger fields.
|
||||||
|
|
||||||
### 0.8.1
|
### 0.8.1
|
||||||
#### Fixed
|
#### Fixed
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -15,7 +15,6 @@ require (
|
|||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/derekparker/trie v0.0.0-20190322172448-1ce4922c7ad9
|
github.com/derekparker/trie v0.0.0-20190322172448-1ce4922c7ad9
|
||||||
github.com/gobwas/glob v0.2.3
|
github.com/gobwas/glob v0.2.3
|
||||||
github.com/gofrs/uuid v3.2.0+incompatible
|
|
||||||
github.com/google/go-cmp v0.2.0 // indirect
|
github.com/google/go-cmp v0.2.0 // indirect
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20190328170749-bb2674552d8f // indirect
|
github.com/gopherjs/gopherjs v0.0.0-20190328170749-bb2674552d8f // indirect
|
||||||
github.com/gorilla/css v1.0.0
|
github.com/gorilla/css v1.0.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -26,8 +26,6 @@ github.com/derekparker/trie v0.0.0-20190322172448-1ce4922c7ad9 h1:aSaTVlEXc2QKl4
|
|||||||
github.com/derekparker/trie v0.0.0-20190322172448-1ce4922c7ad9/go.mod h1:D6ICZm05D9VN1n/8iOtBxLpXtoGp6HDFUJ1RNVieOSE=
|
github.com/derekparker/trie v0.0.0-20190322172448-1ce4922c7ad9/go.mod h1:D6ICZm05D9VN1n/8iOtBxLpXtoGp6HDFUJ1RNVieOSE=
|
||||||
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||||
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
|
|
||||||
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
|
||||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
@@ -48,8 +46,6 @@ github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8
|
|||||||
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
|
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
|
||||||
github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0=
|
github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0=
|
||||||
github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
|
github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
|
||||||
github.com/mafredri/cdp v0.23.4 h1:ffp4qq6slfCL4rFWBDeRHapkLE776gER4tX5Z3LS8CY=
|
|
||||||
github.com/mafredri/cdp v0.23.4/go.mod h1:hgdiA0yp1uqhSaDOHJWPgXpMbh+LAfUdD9vbN2AM8gE=
|
|
||||||
github.com/mafredri/cdp v0.24.2 h1:Rzhj/EQw9opbiwUpNML7P+4Hvf0/nSYPaDbiCEpILOM=
|
github.com/mafredri/cdp v0.24.2 h1:Rzhj/EQw9opbiwUpNML7P+4Hvf0/nSYPaDbiCEpILOM=
|
||||||
github.com/mafredri/cdp v0.24.2/go.mod h1:hgdiA0yp1uqhSaDOHJWPgXpMbh+LAfUdD9vbN2AM8gE=
|
github.com/mafredri/cdp v0.24.2/go.mod h1:hgdiA0yp1uqhSaDOHJWPgXpMbh+LAfUdD9vbN2AM8gE=
|
||||||
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
|
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package logging
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/gofrs/uuid"
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -13,6 +13,7 @@ type (
|
|||||||
Options struct {
|
Options struct {
|
||||||
Writer io.Writer
|
Writer io.Writer
|
||||||
Level Level
|
Level Level
|
||||||
|
Fields map[string]interface{}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,19 +28,15 @@ const (
|
|||||||
Disabled
|
Disabled
|
||||||
)
|
)
|
||||||
|
|
||||||
func WithContext(ctx context.Context, opts *Options) context.Context {
|
func WithContext(ctx context.Context, opts Options) context.Context {
|
||||||
id, err := uuid.NewV4()
|
c := zerolog.New(opts.Writer).With().Timestamp()
|
||||||
|
|
||||||
if err != nil {
|
for k, v := range opts.Fields {
|
||||||
panic(err)
|
c = c.Interface(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger := zerolog.New(opts.Writer).
|
logger := c.Logger()
|
||||||
With().
|
logger.Level(zerolog.Level(opts.Level))
|
||||||
Str("id", id.String()).
|
|
||||||
Logger()
|
|
||||||
|
|
||||||
logger.WithLevel(zerolog.Level(opts.Level))
|
|
||||||
|
|
||||||
return logger.WithContext(ctx)
|
return logger.WithContext(ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
Options struct {
|
Options struct {
|
||||||
params map[string]core.Value
|
params map[string]core.Value
|
||||||
logging *logging.Options
|
logging logging.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
Option func(*Options)
|
Option func(*Options)
|
||||||
@@ -22,7 +22,7 @@ type (
|
|||||||
func NewOptions(setters []Option) *Options {
|
func NewOptions(setters []Option) *Options {
|
||||||
opts := &Options{
|
opts := &Options{
|
||||||
params: make(map[string]core.Value),
|
params: make(map[string]core.Value),
|
||||||
logging: &logging.Options{
|
logging: logging.Options{
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
Level: logging.ErrorLevel,
|
Level: logging.ErrorLevel,
|
||||||
},
|
},
|
||||||
@@ -61,6 +61,12 @@ func WithLogLevel(lvl logging.Level) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithLogFields(fields map[string]interface{}) Option {
|
||||||
|
return func(options *Options) {
|
||||||
|
options.logging.Fields = fields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (opts *Options) WithContext(parent context.Context) context.Context {
|
func (opts *Options) WithContext(parent context.Context) context.Context {
|
||||||
ctx := core.ParamsWith(parent, opts.params)
|
ctx := core.ParamsWith(parent, opts.params)
|
||||||
ctx = logging.WithContext(ctx, opts.logging)
|
ctx = logging.WithContext(ctx, opts.logging)
|
||||||
|
|||||||
Reference in New Issue
Block a user