Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix project to compile and enable setting V-level #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Gopkg.lock

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

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "go.uber.org/zap"
version = "1.9.1"

[prune]
go-tests = true
unused-packages = true
67 changes: 57 additions & 10 deletions glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,51 @@ package glog
import (
"fmt"
"os"
"strconv"
"sync"

"go.uber.org/zap"
)

var verbosity Level

func init() {
verbosity.Set("10")
}

var mu sync.Mutex

// Level is a shim
type Level int32

// String is part of the flag.Value interface.
func (l *Level) String() string {
mu.Lock()
defer mu.Unlock()
return strconv.FormatInt(int64(*l), 10)
}

// Get is part of the flag.Value interface.
func (l *Level) Get() interface{} {
mu.Lock()
defer mu.Unlock()
return *l
}

// Set is part of the flag.Value interface.
// Used to set global verbosity level
func (l *Level) Set(value string) error {
v, err := strconv.ParseInt(value, 10, 32)
if err != nil {
return err
}

mu.Lock()
defer mu.Unlock()
*l = Level(v)
return nil
}

// Verbose is a shim
type Verbose bool

Expand All @@ -40,23 +78,32 @@ func Flush() {

// V is a shim
func V(level Level) Verbose {
return Verbose(zap.L().Core().Enabled(zap.DebugLevel))
isEnabled := zap.L().Core().Enabled(zap.DebugLevel)
mu.Lock()
defer mu.Unlock()
return Verbose(level <= verbosity && isEnabled)
}

// Info is a shim
func (v Verbose) Info(args ...interface{}) {
zap.S().Debug(args...)
if v {
zap.S().Debug(args...)
}
}

// Infoln is a shim
func (v Verbose) Infoln(args ...interface{}) {
s := fmt.Sprint(args)
zap.S().Debug(s, "\n")
if v {
s := fmt.Sprint(args...)
zap.S().Debug(s, "\n")
}
}

// Infof is a shim
func (v Verbose) Infof(format string, args ...interface{}) {
zap.S().Debugf(format, args...)
if v {
zap.S().Debugf(format, args...)
}
}

// Info is a shim
Expand All @@ -71,7 +118,7 @@ func InfoDepth(depth int, args ...interface{}) {

// Infoln is a shim
func Infoln(args ...interface{}) {
s := fmt.Sprint(args)
s := fmt.Sprint(args...)
zap.S().Info(s, "\n")
}

Expand All @@ -92,7 +139,7 @@ func WarningDepth(depth int, args ...interface{}) {

// Warningln is a shim
func Warningln(args ...interface{}) {
s := fmt.Sprint(args)
s := fmt.Sprint(args...)
zap.S().Warn(s, "\n")
}

Expand All @@ -113,7 +160,7 @@ func ErrorDepth(depth int, args ...interface{}) {

// Errorln is a shim
func Errorln(args ...interface{}) {
s := fmt.Sprint(args)
s := fmt.Sprint(args...)
zap.S().Error(s, "\n")
}

Expand All @@ -136,7 +183,7 @@ func FatalDepth(depth int, args ...interface{}) {

// Fatalln is a shim
func Fatalln(args ...interface{}) {
s := fmt.Sprint(args)
s := fmt.Sprint(args...)
zap.S().Error(s, "\n")
os.Exit(255)
}
Expand All @@ -161,7 +208,7 @@ func ExitDepth(depth int, args ...interface{}) {

// Exitln is a shim
func Exitln(args ...interface{}) {
s := fmt.Sprint(args)
s := fmt.Sprint(args...)
zap.S().Error(s, "\n")
os.Exit(1)
}
Expand Down
11 changes: 11 additions & 0 deletions vendor/go.uber.org/atomic/.gitignore

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

21 changes: 21 additions & 0 deletions vendor/go.uber.org/atomic/.travis.yml

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

19 changes: 19 additions & 0 deletions vendor/go.uber.org/atomic/LICENSE.txt

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

64 changes: 64 additions & 0 deletions vendor/go.uber.org/atomic/Makefile

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

34 changes: 34 additions & 0 deletions vendor/go.uber.org/atomic/README.md

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

Loading