Skip to content

Commit

Permalink
[gommon] Update gommon/log Fix #84
Browse files Browse the repository at this point in the history
  • Loading branch information
at15 committed Dec 9, 2018
1 parent 8a3bc39 commit 389962c
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 39 deletions.
42 changes: 21 additions & 21 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
name = "github.com/google/go-github"
branch = "master"

# as a dywegb go project, testing out master branch of its dependencies is .. well integration test
[[constraint]]
name = "github.com/dyweb/gommon"
branch = "master"
Expand Down
2 changes: 1 addition & 1 deletion app/git/gommon_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/git/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

const appName = "git"

var log = logutil.NewPackageLogger()
var log, _ = logutil.NewPackageLoggerAndRegistry()

func init() {
Ayi.RegisterAppFactory(appName, func(r Ayi.Registry) (Ayi.App, error) {
Expand Down
2 changes: 1 addition & 1 deletion app/github/gommon_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/github/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

const appName = "github"

var log = logutil.NewPackageLogger()
var log, _ = logutil.NewPackageLoggerAndRegistry()

func init() {
Ayi.RegisterAppFactory(appName, func(r Ayi.Registry) (Ayi.App, error) {
Expand Down
2 changes: 1 addition & 1 deletion app/web/gommon_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/web/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

const appName = "web"

var log = logutil.NewPackageLogger()
var log, _ = logutil.NewPackageLoggerAndRegistry()

func init() {
Ayi.RegisterAppFactory(appName, func(r Ayi.Registry) (Ayi.App, error) {
Expand Down
5 changes: 3 additions & 2 deletions cmd/ayi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const (
configFile = ".ayi.yml"
)

var log = logutil.Registry
var logReg = logutil.Registry()
var log = logutil.Logger()

var (
version string
Expand All @@ -52,7 +53,7 @@ func Main() error {
icli.Name(myname),
icli.Description(mydesc),
icli.Version(buildInfo),
icli.LogRegistry(log),
icli.LogRegistry(logReg),
)
root := cli.Command()
// TODO: go.ice need to disable built in config flag
Expand Down
4 changes: 2 additions & 2 deletions pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

"github.com/spf13/cobra"

"github.com/dyweb/Ayi/config"
"github.com/dyweb/Ayi/util/logutil"
"github.com/dyweb/gommon/errors"
"github.com/dyweb/Ayi/config"
)

var log = logutil.NewPackageLogger()
var log, _ = logutil.NewPackageLoggerAndRegistry()

var (
appMu sync.Mutex
Expand Down
24 changes: 16 additions & 8 deletions util/logutil/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ import (
"github.com/dyweb/gommon/log"
)

// Registry is the root logger of Ayi application
var Registry = log.NewApplicationLogger()
const Project = "github.com/dyweb/Ayi"

// NewPackageLogger create a new logger for the calling package using Registry as its parent
func NewPackageLogger() *log.Logger {
l := log.NewPackageLoggerWithSkip(1)
Registry.AddChild(l)
return l
var logger, registry = log.NewApplicationLoggerAndRegistry(Project)

func Registry() *log.Registry {
return registry
}

func Logger() *log.Logger {
return logger
}

func NewPackageLoggerAndRegistry() (*log.Logger, *log.Registry) {
logger, child := log.NewPackageLoggerAndRegistryWithSkip(Project, 1)
registry.AddRegistry(child)
return logger, child
}

// add go.ice log registry as its child
func init() {
Registry.AddChild(ilog.Registry)
registry.AddRegistry(ilog.Registry())
}

0 comments on commit 389962c

Please sign in to comment.