Skip to content

Commit

Permalink
up: update New(), can with option func
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 7, 2023
1 parent 796522d commit cc218e0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go_version: [1.19, 1.18]
go_version: [1.19, 1.18, '1.20']
os: [ubuntu-latest, windows-latest] # , macOS-latest

steps:
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ NAME := slog
BUILD_TARGET = testdata
MAIN_SRC_FILE=cmd/main.go
GO :=go
GO_NOMOD :=GO111MODULE=off go
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')

ORG := gookit
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
ORG_REPO := $(ORG)/$(NAME)
RELEASE_ORG_REPO := $(ORG_REPO)
ROOT_PACKAGE := github.com/$(ORG_REPO)

GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/,*.go)

Expand Down Expand Up @@ -76,8 +77,8 @@ help:
full: check ## Build and run the tests
check: build test ## Build and run the tests
get-test-deps: ## Install test dependencies
$(GO_NOMOD) get github.com/axw/gocov/gocov
$(GO_NOMOD) get -u gopkg.in/matm/v1/gocov-html
get install github.com/axw/gocov/gocov
get install gopkg.in/matm/v1/gocov-html

print-version: ## Print version
@echo $(VERSION)
Expand Down Expand Up @@ -157,7 +158,7 @@ clean: ## Clean the generated artifacts
rm -rf build release dist

get-fmt-deps: ## Install test dependencies
$(GO_NOMOD) get golang.org/x/tools/cmd/goimports
get install golang.org/x/tools/cmd/goimports

.PHONY: fmt
fmt: importfmt ## Format the code
Expand Down
4 changes: 2 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type Logger struct {
}

// New create a new logger
func New() *Logger {
return NewWithName("logger")
func New(fns ...LoggerFn) *Logger {
return NewWithName("logger", fns...)
}

// NewWithHandlers create a new logger with handlers
Expand Down
23 changes: 15 additions & 8 deletions sugared.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ type SugaredLogger struct {
}

// NewStdLogger instance
func NewStdLogger() *SugaredLogger {
return NewSugaredLogger(os.Stdout, DebugLevel, func(sl *SugaredLogger) {
sl.SetName("stdLogger")
// sl.CallerSkip += 1
sl.ReportCaller = true
// auto enable console color
sl.Formatter.(*TextFormatter).EnableColor = color.SupportColor()
})
func NewStdLogger(fns ...SugaredLoggerFn) *SugaredLogger {
setFns := []SugaredLoggerFn{
func(sl *SugaredLogger) {
sl.SetName("stdLogger")
// sl.CallerSkip += 1
sl.ReportCaller = true
// auto enable console color
sl.Formatter.(*TextFormatter).EnableColor = color.SupportColor()
},
}

if len(fns) > 0 {
setFns = append(setFns, fns...)
}
return NewSugaredLogger(os.Stdout, DebugLevel, setFns...)
}

// NewSugaredLogger create new SugaredLogger
Expand Down

0 comments on commit cc218e0

Please sign in to comment.