From 4f4ee4afacdd0294bb920ae31cf78eaec186067c Mon Sep 17 00:00:00 2001 From: jiyoungcheon Date: Fri, 3 Jan 2025 01:56:20 -0500 Subject: [PATCH] log added with theccinnamon joy4 --- go.mod | 3 ++ icshttp/handler.go | 24 +++++++++++--- icslog/logoutput.go | 78 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d61e4b7..e14f4d3 100644 --- a/go.mod +++ b/go.mod @@ -11,3 +11,6 @@ require ( golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb ) +replace ( + gitlab.com/ics_cinnamon/joy4 => ../joy4 +) diff --git a/icshttp/handler.go b/icshttp/handler.go index d897324..80f2aaf 100644 --- a/icshttp/handler.go +++ b/icshttp/handler.go @@ -107,6 +107,7 @@ type ScenarioSession struct { var handles []*handleInfo var session []*ScenarioSession var tokenMap map[string]string +var customerTelno string func init() { handles = make([]*handleInfo, HANDLE_NUM) @@ -155,7 +156,7 @@ func TTSFunc2(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "TTS func 2", r) } -//post +// post func TTSFunc3(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "TTS func 3", r) body := make([]byte, r.ContentLength) @@ -167,7 +168,7 @@ func TTSFunc3(w http.ResponseWriter, r *http.Request) { fmt.Println(string(body)) } -//post +// post func TTSFunc4(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "TTS func 4", r) } @@ -196,8 +197,8 @@ func (s *ScenarioSession) GetScnario(dnis string, count int) icsconf.ScenarioCon return resultConfig } -///////////////////////////////////////////// -//BOT +// /////////////////////////////////////////// +// BOT func (s *ScenarioSession) BOTPFunc(w http.ResponseWriter, r *http.Request) { // get scenario config l := icslog.GetIcsLog() @@ -262,15 +263,30 @@ func (s *ScenarioSession) BOTPFunc(w http.ResponseWriter, r *http.Request) { // fmt.Printf("lv 2 =>%#v\n", response) // fmt.Println("-------------------------") + if customerTelno == "" { + customerTelno = request.TelNo + } + if translateinfo.Use { srcSession := s.GetSession(request.Token) dstSession := s.GetSession(translateinfo.Token) if request.TalkText != "" { + if customerTelno == request.TelNo { + l.PrintAnnouce(request.TalkText, true) + } else { + l.PrintAnnouce(request.TalkText, false) + } dstRlt := ResStatus{Count: dstSession.Count + 1, TransLateText: request.TalkText} s.UpdateSession(translateinfo.Token, dstRlt) + response.AnounceMents = request.TalkText } if srcSession.TransLateText != "" { + if customerTelno == request.TelNo { + l.PrintAnnouce(srcSession.TransLateText, false) + } else { + l.PrintAnnouce(srcSession.TransLateText, false) + } response.AnounceMents = srcSession.TransLateText srcRlt := ResStatus{Count: srcSession.Count + 1, Status: scenario.Action, TransLateText: scenario.AnounceMents} s.UpdateSession(request.Token, srcRlt) diff --git a/icslog/logoutput.go b/icslog/logoutput.go index c9861bb..231c99d 100644 --- a/icslog/logoutput.go +++ b/icslog/logoutput.go @@ -183,3 +183,81 @@ func (l *IcsLog) Print(level int, sessionID int, msg string) { l.M.Unlock() } } + +func (l *IcsLog) PrintAnnouce(msg string, customer bool) { + //check disk full + aSpace := icsutil.GetDiskAvailableSpace(filepath.Dir(l.LogFileName)) + if aSpace < uint64(l.conf.Disklimit*ONEMB) { + //if aSpace < uint64(l.conf.LogConfig.Disklimit*ONEMB) { + if !l.IsDiskFull { + msg = fmt.Sprintf("Disk Full! Available Disk Space: %dMB", aSpace/ONEMB) + l.logger.Output(2, msg) + if l.LogFile != nil { + l.LogFile.WriteString(l.buf.String()) + } + l.buf.Reset() + l.IsDiskFull = true + } + return + } + + l.M.Lock() + + if l.checkLogRotate() { + //check log size + stat, err := os.Stat(l.LogFileName) + if err != nil { + msg = fmt.Sprintf("Could not get log file(%s) size", l.LogFileName) + l.logger.Output(2, msg) + if l.LogFile != nil { + l.LogFile.WriteString(l.buf.String()) + } + l.buf.Reset() + + l.M.Unlock() + + return + } + + if stat.Size()/ONEMB >= int64(l.logSize) { + //shift log files + rotateNum := gIcsLog.getTodayLogFileNum() + //fmt.Println("rotate num:", rotateNum, "log size:", stat.Size()/ONEMB, l.logSize) + if rotateNum > 0 && rotateNum < gIcsLog.rotateNum { + gIcsLog.shiftLogFiles(rotateNum) + + l.LogFile.Sync() + l.LogFile.Close() + + //open new log file + var oerr error + l.LogFile, oerr = os.OpenFile(l.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if oerr != nil { + icserror.ICSERRFileOpen.SetError(oerr) + icserror.ICSERRFileOpen.PrintWithCaller(0) + + l.M.Unlock() + return + } + } else { + l.M.Unlock() + return + } + + } + } + var logmsg string + if customer { + logmsg = fmt.Sprintf(">>> %s\n", msg) + } else { + logmsg = fmt.Sprintf("<<< %s\n", msg) + } + + l.logger.Output(2, logmsg) + if l.LogFile != nil { + l.LogFile.WriteString(l.buf.String()) + } + l.buf.Reset() + + l.M.Unlock() +}