Skip to content

Commit

Permalink
update to v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Aug 15, 2020
1 parent 64143aa commit c446908
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Sa 15 August | v0.1.1
## Sa 15 August | v0.1.2

- `Logger.Child` accepts an `interface{}` instead of `string`. This way you can register children for pointers without forcing to naming them. If the key is string, then it's used as prefix (like always did).
- `Logger.Child` accepts an `interface{}` instead of `string`. This way you can register children for pointers without forcing to naming them. If the key is string or completes the `fmt.Stringer` interface, then it's used as prefix (like always did).

## Fr 14 August 2020 | v0.0.19

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module your_project_name
go 1.14

require (
github.com/kataras/golog v0.1.1
github.com/kataras/golog v0.1.2
)
```

Expand Down
22 changes: 19 additions & 3 deletions _examples/child/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"github.com/kataras/golog"
)
import "github.com/kataras/golog"

func main() {

Expand All @@ -15,16 +13,22 @@ func main() {
var (
srvLogger = golog.Child("Server")
app1Logger = srvLogger.Child("App1")

// Or use a pointer as child's key and append the prefix manually:
app2 = newApp("App2")
app2Logger = srvLogger.Child(app2).
SetChildPrefix(app2.Name).
SetLevel("debug")

// Or use a pointer to a value which implements the fmt.Stringer:
app3 = newAppWithString("App3")
app3Logger = srvLogger.Child(app3)
)

srvLogger.Infof("Hello Server")
app1Logger.Infof("Hello App1")
app2Logger.Debugf("Hello App2")
app3Logger.Warnf("Hello App3")
}

type app struct {
Expand All @@ -34,3 +38,15 @@ type app struct {
func newApp(name string) *app {
return &app{Name: name}
}

type appWithString struct {
name string
}

func newAppWithString(name string) *appWithString {
return &appWithString{name: name}
}

func (app *appWithString) String() string {
return app.name
}
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Source code and other details for the project are available at GitHub:
Current Version
0.0.19
0.1.2
Installation
Expand Down Expand Up @@ -390,4 +390,4 @@ Examples:
package golog // import "github.com/kataras/golog"

// Version is the version string representation of the "golog" package.
const Version = "0.1.1"
const Version = "0.1.2"
9 changes: 7 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,14 @@ func (m *loggerMap) getOrAdd(key interface{}, parent *Logger) *Logger {
}

logger = parent.Clone()
if prefix, ok := key.(string); ok {
logger.SetChildPrefix(prefix)
childPrefix := ""
switch v := key.(type) {
case string:
childPrefix = v
case fmt.Stringer:
childPrefix = v.String()
}
logger.SetChildPrefix(childPrefix)

m.mu.Lock()
m.Items[key] = logger
Expand Down

0 comments on commit c446908

Please sign in to comment.