log 변경

main
JungJun 3 years ago
parent 09bab32589
commit a97c1c22bd

@ -87,9 +87,9 @@ func (l *IcsLog) Printf(level int, sessionID int, format string, a ...interface{
} }
var logmsg string var logmsg string
if sessionID >= 0 { if sessionID >= 0 {
logmsg = fmt.Sprintf("[%s][%03d]> %s", IcsLogLevelStr[level], sessionID, msg) logmsg = fmt.Sprintf("%s", msg)
} else { } else {
logmsg = fmt.Sprintf("[%s][-1]> %s", IcsLogLevelStr[level], msg) logmsg = fmt.Sprintf("%s", msg)
} }
l.logger.Output(2, logmsg) l.logger.Output(2, logmsg)
@ -173,9 +173,9 @@ func (l *IcsLog) Print(level int, sessionID int, msg string) {
} }
var logmsg string var logmsg string
if sessionID >= 0 { if sessionID >= 0 {
logmsg = fmt.Sprintf("[%s][%03d]> %s", IcsLogLevelStr[level], sessionID, msg) logmsg = fmt.Sprintf("%s", msg)
} else { } else {
logmsg = fmt.Sprintf("[%s][-1]> %s", IcsLogLevelStr[level], msg) logmsg = fmt.Sprintf("%s", msg)
} }
l.logger.Output(2, logmsg) l.logger.Output(2, logmsg)
if l.LogFile != nil { if l.LogFile != nil {

@ -36,6 +36,10 @@ type StatInfos struct {
SvcType string // 20 SvcType string // 20
SvcReqTime string // 17 SvcReqTime string // 17
SvcRspTime string // 17 SvcRspTime string // 17
TransferNo string // 20
CallTime string // 5
CallType string // 10
FunName string // 30
ResultMsg string // 256 ResultMsg string // 256
SttText string // 8192 SttText string // 8192
TtsText string // 1024 TtsText string // 1024
@ -43,7 +47,6 @@ type StatInfos struct {
const ( const (
//necessary value //necessary value
STAT_INFO = 0 STAT_INFO = 0
SEQ_ID = STAT_INFO + 25 SEQ_ID = STAT_INFO + 25
LOG_TIME = SEQ_ID + 14 LOG_TIME = SEQ_ID + 14
@ -69,9 +72,13 @@ const (
SVC_TYPE = CONC_CALL + 20 SVC_TYPE = CONC_CALL + 20
SVC_REQ_TIME = SVC_TYPE + 17 SVC_REQ_TIME = SVC_TYPE + 17
SVC_RSP_TIME = SVC_REQ_TIME + 17 SVC_RSP_TIME = SVC_REQ_TIME + 17
RESULT_MSG = SVC_RSP_TIME + 17 TRANSFER_NO = SVC_RSP_TIME + 20
STT_TEXT = RESULT_MSG + 256 CALL_TIME = TRANSFER_NO + 5
TTS_TEXT = STT_TEXT + 8192 //slice 86..? CALL_TYPE = CALL_TIME + 10
FUN_NAME = CALL_TYPE + 30
RESULT_MSG = FUN_NAME + 255
STT_TEXT = RESULT_MSG + 8192
TTS_TEXT = STT_TEXT + 1024
) )
func ListenStatMNG() (icserr *icserror.IcsError) { func ListenStatMNG() (icserr *icserror.IcsError) {
@ -85,7 +92,7 @@ func ListenStatMNG() (icserr *icserror.IcsError) {
statLocalAddr := icsnet.NewNetAddrWithIPAddr(statLocalAddrStr) statLocalAddr := icsnet.NewNetAddrWithIPAddr(statLocalAddrStr)
var cmdErr *icserror.IcsError var cmdErr *icserror.IcsError
statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n\r\n", BotCommand) statTCP, cmdErr := icsnet.ListenAndServeTCP(&statLocalAddr, nil, "\r\n\r\n", StatsCommand)
if cmdErr != nil { if cmdErr != nil {
l.Printf(icslog.LOG_LEVEL_FATAL, -1, "%s", cmdErr.GetError()) l.Printf(icslog.LOG_LEVEL_FATAL, -1, "%s", cmdErr.GetError())
return nil return nil
@ -96,52 +103,61 @@ func ListenStatMNG() (icserr *icserror.IcsError) {
return nil return nil
} }
func BotCommand(t *icsnet.IcsTCPNet, bufend string) { func StatsCommand(t *icsnet.IcsTCPNet, bufend string) {
l := icslog.GetIcsLog() l := icslog.GetIcsLog()
statInfos := new(StatInfos) statInfos := new(StatInfos)
count := 0
defer t.Close() defer t.Close()
l.Printf(icslog.LOG_LEVEL_INFO, -1, "Connected from - %s", t.RemoteAddr()) l.Printf(icslog.LOG_LEVEL_INFO, -1, "Connected from - %s", t.RemoteAddr())
for { for {
statReads, rlen, rerr := t.ReadS(10018, bufend) // 여기서 전체 몇 byte씩 읽어서 로그를 찍을건지 알아야함 statReads, rlen, rerr := t.ReadS(10137, bufend) // 여기서 전체 몇 byte씩 읽어서 로그를 찍을건지 알아야함
if rerr != nil { if rerr != nil {
if rerr.GetError() != io.EOF { if rerr.GetError() != io.EOF {
l.Printf(icslog.LOG_LEVEL_ERROR, -1, "[Stat Command] ReadS Error! - %s[%d:%d]", l.Printf(icslog.LOG_LEVEL_ERROR, -1, "[Stat Command] ReadS Error! - %s[%d:%d]",
rerr.GetError(), rlen, len(statReads)) rerr.GetError(), rlen, len(statReads))
// t.Close()
} }
break continue
} else { } else {
seqId := fmt.Sprintf("%05d", count)
fmt.Printf("Recved Stat Command(%s) %d \n", statReads, rlen) fmt.Printf("Recved Stat Command(%s) %d \n", statReads, rlen)
statInfos.ChangeByteToString(statReads) statInfos.ChangeByteToString(statReads)
insLog := "" insLog := ""
insLog += fmt.Sprintf("%s\n", statInfos.CallId) // insLog += fmt.Sprintf("%s\n", statInfos.CallId)
insLog += fmt.Sprintf("%s\n", statInfos.SeqId) insLog += fmt.Sprintf("seqId:%s\n", seqId)
insLog += fmt.Sprintf("%s\n", statInfos.LogTime) // insLog += fmt.Sprintf("%s\n", statInfos.SeqId)
insLog += fmt.Sprintf("%s\n", statInfos.LogType) insLog += fmt.Sprintf("LogTime:%s, ", statInfos.LogTime)
insLog += fmt.Sprintf("%s\n", statInfos.Sid) insLog += fmt.Sprintf("LogType:%s, ", statInfos.LogType)
insLog += fmt.Sprintf("%s\n", statInfos.ResultCode) insLog += fmt.Sprintf("Sid:%s, ", statInfos.Sid)
insLog += fmt.Sprintf("%s\n", statInfos.ReqTime) insLog += fmt.Sprintf("ResultCode:%s, ", statInfos.ResultCode)
insLog += fmt.Sprintf("%s\n", statInfos.RspTime) insLog += fmt.Sprintf("ReqTime:%s, ", statInfos.ReqTime)
insLog += fmt.Sprintf("%s\n", statInfos.ClientIp) insLog += fmt.Sprintf("RspTime:%s, ", statInfos.RspTime)
insLog += fmt.Sprintf("%s\n", statInfos.DevInfo) insLog += fmt.Sprintf("ClientIp:%s, ", statInfos.ClientIp)
insLog += fmt.Sprintf("%s\n", statInfos.OsInfo) insLog += fmt.Sprintf("DevInfo:%s, ", statInfos.DevInfo)
insLog += fmt.Sprintf("%s\n", statInfos.NwInfo) insLog += fmt.Sprintf("OsInfo:%s, ", statInfos.OsInfo)
insLog += fmt.Sprintf("%s\n", statInfos.SvcName) insLog += fmt.Sprintf("NwInfo:%s, ", statInfos.NwInfo)
insLog += fmt.Sprintf("%s\n", statInfos.DevModel) insLog += fmt.Sprintf("SvcName:%s, ", statInfos.SvcName)
insLog += fmt.Sprintf("%s\n", statInfos.CarrierType) insLog += fmt.Sprintf("DevModel:%s, ", statInfos.DevModel)
insLog += fmt.Sprintf("%s\n", statInfos.HostName) insLog += fmt.Sprintf("CarrierType:%s, ", statInfos.CarrierType)
insLog += fmt.Sprintf("%s\n", statInfos.ScnName) insLog += fmt.Sprintf("HostName:%s, ", statInfos.HostName)
insLog += fmt.Sprintf("%s\n", statInfos.CallId) insLog += fmt.Sprintf("ScnName:%s, ", statInfos.ScnName)
insLog += fmt.Sprintf("%s\n", statInfos.TrId) insLog += fmt.Sprintf("CallId:%s, ", statInfos.CallId)
insLog += fmt.Sprintf("%s\n", statInfos.ConcCall) insLog += fmt.Sprintf("TrId:%s, ", statInfos.TrId)
insLog += fmt.Sprintf("%s\n", statInfos.SvcType) insLog += fmt.Sprintf("ConcCall:%s, ", statInfos.ConcCall)
insLog += fmt.Sprintf("%s\n", statInfos.SvcReqTime) insLog += fmt.Sprintf("SvcType:%s, ", statInfos.SvcType)
insLog += fmt.Sprintf("%s\n", statInfos.SvcRspTime) insLog += fmt.Sprintf("SvcReqTime:%s, ", statInfos.SvcReqTime)
insLog += fmt.Sprintf("%s\n", statInfos.ResultMsg) insLog += fmt.Sprintf("SvcRspTime:%s, ", statInfos.SvcRspTime)
insLog += fmt.Sprintf("%s\n", statInfos.SttText) insLog += fmt.Sprintf("TransferNo:%s, ", statInfos.TransferNo)
insLog += fmt.Sprintf("%s\n", statInfos.TtsText) insLog += fmt.Sprintf("CallTime:%s, ", statInfos.CallTime)
insLog += fmt.Sprintf("CallType:%s, ", statInfos.CallType)
insLog += fmt.Sprintf("FunName:%s, ", statInfos.FunName)
insLog += fmt.Sprintf("ResultMsg:%s, ", statInfos.ResultMsg)
insLog += fmt.Sprintf("SttText:%s, ", statInfos.SttText)
insLog += fmt.Sprintf("TtsText:%s", statInfos.TtsText)
l.Printf(icslog.LOG_LEVEL_INFO, -1, "%s", insLog) l.Printf(icslog.LOG_LEVEL_INFO, -1, "%s", insLog)
fmt.Printf("stats- %s \n", statInfos.SeqId) fmt.Printf("stats- %s \n", statInfos.SeqId)
@ -166,15 +182,29 @@ func BotCommand(t *icsnet.IcsTCPNet, bufend string) {
fmt.Printf("stats- %s \n", statInfos.SvcType) fmt.Printf("stats- %s \n", statInfos.SvcType)
fmt.Printf("stats- %s \n", statInfos.SvcReqTime) fmt.Printf("stats- %s \n", statInfos.SvcReqTime)
fmt.Printf("stats- %s \n", statInfos.SvcRspTime) fmt.Printf("stats- %s \n", statInfos.SvcRspTime)
fmt.Printf("stats- %s \n", statInfos.TransferNo)
fmt.Printf("stats- %s \n", statInfos.CallTime)
fmt.Printf("stats- %s \n", statInfos.CallType)
fmt.Printf("stats- %s \n", statInfos.FunName)
fmt.Printf("stats- %s \n", statInfos.ResultMsg) fmt.Printf("stats- %s \n", statInfos.ResultMsg)
fmt.Printf("stats- %s \n", statInfos.SttText) fmt.Printf("stats- %s \n", statInfos.SttText)
fmt.Printf("stats- %s \n", statInfos.TtsText) fmt.Printf("stats- %s \n", statInfos.TtsText)
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Recved Stat Command(%s) %d", ttsHeader, rlen) // l.Printf(icslog.LOG_LEVEL_INFO, -1, "Recved Stat Command(%s) %d", ttsHeader, rlen)
count++
// t.Close()
} }
} }
} }
func (statInfos *StatInfos) ChangeByteToString(statInfo []byte) { func (statInfos *StatInfos) ChangeByteToString(statInfo []byte) *icserror.IcsError {
// l := icslog.GetIcsLog()
// defer func() {
// l.Printf(icslog.LOG_LEVEL_WARN, -1, "%s \n%s",
// icserror.ICSERRNETNotConnectError.GetMessage(), debug.Stack())
// return
// }()
// n := bytes.Index(statInfo[STAT_INFO:SEQ_ID], []byte{0}) // n := bytes.Index(statInfo[STAT_INFO:SEQ_ID], []byte{0})
statInfos.SeqId = string(statInfo[STAT_INFO:SEQ_ID]) statInfos.SeqId = string(statInfo[STAT_INFO:SEQ_ID])
// fmt.Println("seqid ", statInfo[STAT_INFO : SEQ_ID]) // fmt.Println("seqid ", statInfo[STAT_INFO : SEQ_ID])
@ -244,8 +274,20 @@ func (statInfos *StatInfos) ChangeByteToString(statInfo []byte) {
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0}) // n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.SvcRspTime = string(statInfo[SVC_REQ_TIME:SVC_RSP_TIME]) statInfos.SvcRspTime = string(statInfo[SVC_REQ_TIME:SVC_RSP_TIME])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.TransferNo = string(statInfo[SVC_RSP_TIME:TRANSFER_NO])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.CallTime = string(statInfo[TRANSFER_NO:CALL_TIME])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.CallType = string(statInfo[CALL_TIME:CALL_TYPE])
// n = bytes.Index(statInfo[SVC_REQ_TIME:SVC_RSP_TIME], []byte{0})
statInfos.FunName = string(statInfo[CALL_TYPE:FUN_NAME])
// n = bytes.Index(statInfo[SVC_RSP_TIME:RESULT_MSG], []byte{0}) // n = bytes.Index(statInfo[SVC_RSP_TIME:RESULT_MSG], []byte{0})
statInfos.ResultMsg = string(statInfo[SVC_RSP_TIME:RESULT_MSG]) statInfos.ResultMsg = string(statInfo[FUN_NAME:RESULT_MSG])
// n = bytes.Index(statInfo[RESULT_MSG:STT_TEXT], []byte{0}) // n = bytes.Index(statInfo[RESULT_MSG:STT_TEXT], []byte{0})
statInfos.SttText = string(statInfo[RESULT_MSG:STT_TEXT]) statInfos.SttText = string(statInfo[RESULT_MSG:STT_TEXT])
@ -253,4 +295,5 @@ func (statInfos *StatInfos) ChangeByteToString(statInfo []byte) {
// n = bytes.Index(statInfo[STT_TEXT:TTS_TEXT], []byte{0}) // n = bytes.Index(statInfo[STT_TEXT:TTS_TEXT], []byte{0})
statInfos.TtsText = string(statInfo[STT_TEXT:]) statInfos.TtsText = string(statInfo[STT_TEXT:])
return nil
} }

Loading…
Cancel
Save