@@ -11,8 +11,9 @@ import (
1111var (
1212 bEnableLog bool = false
1313 logchan chan string
14- bShowInConsole bool = false
15- arrLogType = [... ]string {"normal" , "warning" , "error" }
14+ bShowInConsole bool = false
15+ arrLogType = [... ]string {"normal" , "warning" , "error" }
16+ mapLogPath map [int ]string = make (map [int ]string )
1617 logPath string
1718)
1819
@@ -23,15 +24,20 @@ func InitLog() {
2324 bShowInConsole = config .GConfig .LogCfg .ShowInConsole
2425 fmt .Println ("Log path from config file:" + config .GConfig .LogCfg .LogPath )
2526 logPath = config .GConfig .LogCfg .LogPath
26- //check if the logPath exists
27- if err := file .FolderExists (logPath ); err != nil {
28- if err = file .CreateFolder (logPath ); err != nil {
29- panic (err )
30- }
27+ for key , val := range arrLogType {
28+ checkAndCreateFolder (logPath + "/" + val + "/" , key )
3129 }
3230 go Listen4Log ()
3331}
3432
33+ func checkAndCreateFolder (path string , pos int ) {
34+ if err := file .FolderExists (path ); err != nil {
35+ if err = file .CreateFolder (path ); err != nil {
36+ panic (err )
37+ }
38+ }
39+ mapLogPath [pos ] = path
40+ }
3541func wlog (info string ) {
3642 logchan <- info
3743}
@@ -43,16 +49,17 @@ func Listen4Log() {
4349 select {
4450 case recvStr = <- logchan :
4551 logType := recvStr [0 :1 ]
52+ rawContent := recvStr [1 :]
4653 if iType , err = strconv .Atoi (logType ); err != nil {
4754 iType = 0
4855 fmt .Printf ("error logType in Listen4Log [%s]\n " , logType )
4956 }
5057 if bShowInConsole {
5158 fmt .Printf ("[%s][%s] %s\n " ,
52- gtime .GetCurTime (gtime .BASIC_MILL ), arrLogType [iType ], recvStr [ 1 :] )
59+ gtime .GetCurTime (gtime .BASIC_MILL ), arrLogType [iType ], rawContent )
5360 }
54- //file.SaveFile(logPath+"firstFile", "Hello World" )
55- file .AddContent2File (logPath + "firstFile" , "Hello World " )
61+ filePath := mapLogPath [ iType ] + gtime . GetCurDate ( gtime . STYLE1 )
62+ file .AddContent2File (filePath , rawContent + " \n " )
5663 }
5764}
5865
0 commit comments