log project shared
This commit is contained in:
commit
9818da5c38
30
.gitignore
vendored
Normal file
30
.gitignore
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Go template
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
||||
|
||||
.idea/
|
||||
log.iml
|
85
log.go
Normal file
85
log.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cihub/seelog"
|
||||
)
|
||||
//var logger seelog.LoggerInterface
|
||||
|
||||
func LoadLogConfig(path string) error {
|
||||
|
||||
//pwd, _ := os.Getwd()
|
||||
|
||||
//path := pwd+"/src/loafle.com/overflow/collector/log/seelogconfig.xml"
|
||||
//var err error
|
||||
|
||||
logger, err := seelog.LoggerFromConfigAsFile(path)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error : ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
seelog.ReplaceLogger(logger)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func Debugf(format string, params ...interface{}) {
|
||||
seelog.Debugf(format, params)
|
||||
}
|
||||
func Tracef(format string, params ...interface{}) {
|
||||
seelog.Tracef(format, params)
|
||||
}
|
||||
func Warnf(format string, params ...interface{}) {
|
||||
seelog.Warnf(format, params)
|
||||
}
|
||||
func Infof(format string, params ...interface{}) {
|
||||
seelog.Infof(format, params)
|
||||
}
|
||||
func Errorf(format string, params ...interface{}) {
|
||||
seelog.Errorf(format, params)
|
||||
}
|
||||
func Criticalf(format string, params ...interface{}) {
|
||||
seelog.Criticalf(format, params)
|
||||
}
|
||||
|
||||
|
||||
//func Fatalf(format string, params ...interface{}) {
|
||||
// seelog.Criticalf(format, params)
|
||||
// os.Exit(1)
|
||||
//}
|
||||
|
||||
func Debug(v ...interface{}) {
|
||||
seelog.Debug(v)
|
||||
}
|
||||
|
||||
func Trace(v ...interface{}) {
|
||||
seelog.Trace(v)
|
||||
}
|
||||
|
||||
func Warn(v ...interface{}) {
|
||||
seelog.Warn(v)
|
||||
}
|
||||
|
||||
func Info(v ...interface{}) {
|
||||
seelog.Info(v)
|
||||
}
|
||||
|
||||
func Error(v ...interface{}) {
|
||||
seelog.Error(v)
|
||||
}
|
||||
|
||||
func Critical(v ...interface{}) {
|
||||
seelog.Critical(v)
|
||||
}
|
||||
|
||||
//func Fatal(v ...interface{}) {
|
||||
// logger.Critical(v)
|
||||
// os.Exit(1)
|
||||
//}
|
||||
|
||||
func Flush() {
|
||||
seelog.Flush()
|
||||
}
|
||||
|
27
log_test.go
Normal file
27
log_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func TestLoadLogConfig(t *testing.T) {
|
||||
path := "./seelogconfig.xml"
|
||||
|
||||
err := LoadLogConfig(path)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error Config")
|
||||
}
|
||||
|
||||
defer Flush()
|
||||
|
||||
Debug("Debugddddddddd")
|
||||
Warn("Warnddddd")
|
||||
Error("Errorddddd")
|
||||
Info("Infoddd")
|
||||
Critical("Criticalddd")
|
||||
//Fatal("Fatal")
|
||||
|
||||
|
||||
}
|
12
seelogconfig.xml
Normal file
12
seelogconfig.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<seelog type="asynctimer" asyncinterval="1000">
|
||||
<outputs>
|
||||
<!--<file path="./log/seelog/prototype/seelog.log" formatid="testFormat"/>-->
|
||||
<console formatid="basicTime" />
|
||||
<rollingfile formatid="basicTime" type="date" filename="./logs/log" maxrolls="5"
|
||||
datepattern="02.01.2006.15" archivetype="zip" fullname="true" archivepath="./logs/archives/"/>
|
||||
</outputs>
|
||||
<formats>
|
||||
<!--<format id="basicTime" format="%EscM(34)%Date/%Time %Func [%Level] %Msg%n"/>-->
|
||||
<format id="basicTime" format="%EscM(34)%Date/%Time [%LEV] %RelFile:%Line %Func()-%Msg%n"/>
|
||||
</formats>
|
||||
</seelog>
|
Loading…
Reference in New Issue
Block a user