From 0e0b3a4b1748f3ffdea565052798972e5d9519b7 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 16 Aug 2020 16:00:39 +0800 Subject: [PATCH] 51 --- Limit.go | 21 +++++++++++++++++---- Log.go | 10 ++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Limit.go b/Limit.go index ae46d1e..80957b7 100644 --- a/Limit.go +++ b/Limit.go @@ -14,14 +14,27 @@ type Limitl struct { func Limit(Max,Second,TimeOut int) (*Limitl) { - returnVal := Limitl{} - if Max < 1 || Second < 1 || TimeOut < Second{return &returnVal} + // Logf().NoShow(false) - returnVal = Limitl{ + if Max < 1 { + Logf().E("Limit:Max < 1 is true.Set to 1") + Max = 1 + } + + returnVal := Limitl{ Max:Max, + Channl:make(chan bool,Max), + } + + if Second < 1 || TimeOut < Second{ + Logf().E("Limit:Second < 1 || TimeOut < Second is true.Set Stop to true") + returnVal.Stop = true + return &returnVal + } + + returnVal = Limitl{ Second:Second, TimeOut:TimeOut, - Channl:make(chan bool,Max), } go func(returnVal *Limitl){ diff --git a/Log.go b/Log.go index 1b6c1e5..0818ed7 100644 --- a/Log.go +++ b/Log.go @@ -9,6 +9,7 @@ import ( type logl struct { fileName string + noShow bool channelN chan int channel chan interface{} wantLog chan bool @@ -84,6 +85,7 @@ func (l *logl) New(fileP string) { for len(l.channelN) != 0 { i := <- l.channelN + if l.noShow {continue} switch i { case -1: l.Close() @@ -106,6 +108,10 @@ func (l *logl) New(fileP string) { }() } +func (l *logl) NoShow(NoShow bool){ + l.noShow = NoShow +} + func (l *logl) Close(){ l.fileName = "" } @@ -117,24 +123,28 @@ func (l *logl) WClose(){ } func (l *logl) T(i ...interface{}){ + if l.noShow {return} if l.fileName == "" {log.Println("TRACE:", i);return} l.channelN <- 0 l.channel <- i if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true} } func (l *logl) I(i ...interface{}){ + if l.noShow {return} if l.fileName == "" {log.Println("INFO:", i);return} l.channelN <- 1 l.channel <- i if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true} } func (l *logl) W(i ...interface{}){ + if l.noShow {return} if l.fileName == "" {log.Println("WARNING:", i);return} l.channelN <- 2 l.channel <- i if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true} } func (l *logl) E(i ...interface{}){ + if l.noShow {return} if l.fileName == "" {log.Println("ERROR:", i);return} l.channelN <- 3 l.channel <- i -- 2.39.2