log added with theccinnamon joy4

jiyoung
jiyoungcheon 3 weeks ago
parent f0b490e2b2
commit 4f4ee4afac

@ -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
)

@ -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)

@ -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()
}

Loading…
Cancel
Save