Skip to content

Commit

Permalink
修正采用wg来协同
Browse files Browse the repository at this point in the history
  • Loading branch information
y-omicron committed Jul 29, 2022
1 parent 2a5df1c commit b985a36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
15 changes: 9 additions & 6 deletions Log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func Warning(cStr string, args ...any) {
logContext.wg.Add(1)
}
func Info(cStr string, args ...any) {
logContext.wg.Add(1)
if logContext.IsFile {
logContext.wg.Add(1)
fMsg := fmt.Sprintf("%s [ info ] %s", time.Now().Format(timeFormatLayout), cStr)
logContext.fMsg <- fmt.Sprintf(fMsg, args...)
}
Expand All @@ -136,8 +136,8 @@ func Info(cStr string, args ...any) {
logContext.wg.Add(1)
}
func Debug(cStr string, args ...any) {
logContext.wg.Add(1)
if logContext.IsFile {
logContext.wg.Add(1)
fMsg := fmt.Sprintf("%s [ debug ] %s", time.Now().Format(timeFormatLayout), cStr)
logContext.fMsg <- fmt.Sprintf(fMsg, args...)
}
Expand All @@ -149,8 +149,8 @@ func Debug(cStr string, args ...any) {
logContext.wg.Add(1)
}
func Trace(cStr string, args ...any) {
logContext.wg.Add(1)
if logContext.IsFile {
logContext.wg.Add(1)
fMsg := fmt.Sprintf("%s [ trace ] %s", time.Now().Format(timeFormatLayout), cStr)
logContext.fMsg <- fmt.Sprintf(fMsg, args...)
}
Expand All @@ -162,8 +162,9 @@ func Trace(cStr string, args ...any) {
logContext.wg.Add(1)
}
func Error(cStr string, args ...any) {
logContext.wg.Add(1)
if logContext.IsFile {
logContext.wg.Add(1)

fMsg := fmt.Sprintf("%s [ error ] %s", time.Now().Format(timeFormatLayout), cStr)
logContext.fMsg <- fmt.Sprintf(fMsg, args...)
}
Expand All @@ -172,8 +173,9 @@ func Error(cStr string, args ...any) {
logContext.wg.Add(1)
}
func Fatal(cStr string, args ...any) {
logContext.wg.Add(1)
if logContext.IsFile {
logContext.wg.Add(1)

fMsg := fmt.Sprintf("%s [ fatal ] %s", time.Now().Format(timeFormatLayout), cStr)
logContext.fMsg <- fmt.Sprintf(fMsg, args...)
}
Expand All @@ -183,8 +185,9 @@ func Fatal(cStr string, args ...any) {
os.Exit(0)
}
func Success(cStr string, args ...any) {
logContext.wg.Add(1)
if logContext.IsFile {
logContext.wg.Add(1)

fMsg := fmt.Sprintf("%s [ fatal ] %s", time.Now().Format(timeFormatLayout), cStr)
logContext.fMsg <- fmt.Sprintf(fMsg, args...)
}
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/y-omicron/util

go 1.18

require github.com/gookit/color v1.5.1
require (
github.com/alecthomas/kong v0.6.1
github.com/gookit/color v1.5.1
)

require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
Expand Down
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/alecthomas/kong v0.6.1 h1:1kNhcFepkR+HmasQpbiKDLylIL8yh5B5y1zPp5bJimA=
github.com/alecthomas/kong v0.6.1/go.mod h1:JfHWDzLmbh/puW6I3V7uWenoh56YNVONW+w8eKeUr9I=
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit b985a36

Please sign in to comment.