use logrus to project default log tools
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package common
|
||||
|
||||
type LOG_MODE int
|
||||
|
||||
const (
|
||||
LOG_NIL = 0
|
||||
LOG_FMT = 1
|
||||
//LOG_FILE = 2
|
||||
|
||||
LOG_INFO LOG_MODE = 0
|
||||
LOG_WARN LOG_MODE = 1
|
||||
LOG_ERROR LOG_MODE = 2
|
||||
)
|
||||
|
||||
//session储存头
|
||||
const HEAD_SESSION_ADD = "session#"
|
||||
@@ -1,17 +1,19 @@
|
||||
package common
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ContextBase struct {
|
||||
Error
|
||||
tag int64
|
||||
tag string
|
||||
}
|
||||
|
||||
//唯一标志
|
||||
func (this *ContextBase) GetTag() int64 {
|
||||
func (this *ContextBase) GetTag() string {
|
||||
|
||||
if this.tag == int64(0) {
|
||||
this.tag = time.Now().UnixNano()
|
||||
if this.tag == "" {
|
||||
this.tag = ObjToStr(time.Now().Unix()) + ":" + ObjToStr(Random())
|
||||
}
|
||||
return this.tag
|
||||
}
|
||||
|
||||
+5
-13
@@ -1,25 +1,17 @@
|
||||
package common
|
||||
|
||||
//框架层处理错误
|
||||
// Error 框架层处理错误
|
||||
type Error struct {
|
||||
error
|
||||
err error
|
||||
}
|
||||
|
||||
func (this *Error) GetError() error {
|
||||
func (that *Error) GetError() error {
|
||||
|
||||
return this.error
|
||||
return that.error
|
||||
|
||||
}
|
||||
|
||||
func (this *Error) SetError(err error, loglevel ...int) {
|
||||
|
||||
this.error = nil
|
||||
if err == nil {
|
||||
this.error = err
|
||||
this.err = err
|
||||
return
|
||||
}
|
||||
this.error = err
|
||||
func (that *Error) SetError(err error) {
|
||||
that.error = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package common
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
@@ -25,86 +24,6 @@ import (
|
||||
// return res
|
||||
//}
|
||||
|
||||
//func LogError(logMsg interface{}) {
|
||||
//
|
||||
// logFmt(fmt.Sprintln(logMsg), 2, LOG_ERROR)
|
||||
//}
|
||||
//func LogWarn(logMsg interface{}) {
|
||||
//
|
||||
// logFmt(fmt.Sprintln(logMsg), 2, LOG_WARN)
|
||||
//}
|
||||
//func LogInfo(logMsg ...interface{}) {
|
||||
//
|
||||
// logFmt(fmt.Sprintln(logMsg), 2, LOG_INFO)
|
||||
//}
|
||||
//
|
||||
//func LogFmt(logMsg interface{}, loglevel ...LOG_MODE) {
|
||||
//
|
||||
// logFmt(logMsg, 2, loglevel...)
|
||||
//}
|
||||
//
|
||||
////日志打印以及存储到文件
|
||||
//func logFmt(logMsg interface{}, printLevel int, loglevel ...LOG_MODE) {
|
||||
//
|
||||
// if Config.GetInt("logLevel") == int(LOG_NIL) {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// lev := LOG_INFO
|
||||
// if len(loglevel) != 0 {
|
||||
// lev = loglevel[0]
|
||||
// }
|
||||
// gofile := ""
|
||||
//
|
||||
// if Config.GetInt("debug") != 0 && printLevel != 0 {
|
||||
// _, file, line, ok := runtime.Caller(printLevel)
|
||||
// if ok {
|
||||
// gofile = " " + file + ":" + ObjToStr(line)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// logStr := ""
|
||||
//
|
||||
// if lev == LOG_INFO {
|
||||
// logStr = "info:"
|
||||
// }
|
||||
// if printLevel == 0 {
|
||||
// logStr = "connect:"
|
||||
// }
|
||||
//
|
||||
// if lev == LOG_WARN {
|
||||
// logStr = "warn:"
|
||||
// }
|
||||
//
|
||||
// if lev == LOG_ERROR {
|
||||
// logStr = "error:"
|
||||
// }
|
||||
//
|
||||
// logStr = fmt.Sprintln(time.Now().Format("2006/01/02 15:04:05"), logStr, logMsg, gofile)
|
||||
// //打印日志
|
||||
// fmt.Print(logStr)
|
||||
// //不需要存储到文件
|
||||
// if Config.GetString("logFile") == "" {
|
||||
// return
|
||||
// }
|
||||
// //存储到文件
|
||||
// logFilePath := time.Now().Format(Config.GetString("logFile"))
|
||||
//
|
||||
// os.MkdirAll(filepath.Dir(logFilePath), os.ModeAppend)
|
||||
// //os.Create(logFilePath)
|
||||
// f, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_CREATE, 0644)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// f.Write([]byte(logStr))
|
||||
// f.Close()
|
||||
//
|
||||
//}
|
||||
//日志打印以及存储到文件
|
||||
func LogFmt(logMsg interface{}, printLevel int, loglevel ...LOG_MODE) {
|
||||
fmt.Println(logMsg)
|
||||
}
|
||||
|
||||
//字符串首字符大写
|
||||
func StrFirstToUpper(str string) string {
|
||||
if len(str) == 0 {
|
||||
|
||||
+34
-34
@@ -6,79 +6,79 @@ import (
|
||||
|
||||
type Slice []interface{}
|
||||
|
||||
//获取string
|
||||
func (this Slice) GetString(key int, err ...*Error) string {
|
||||
// GetString 获取string
|
||||
func (that Slice) GetString(key int, err ...*Error) string {
|
||||
if len(err) != 0 {
|
||||
err[0].SetError(nil)
|
||||
}
|
||||
return ObjToStr((this)[key])
|
||||
return ObjToStr((that)[key])
|
||||
}
|
||||
|
||||
//获取Int
|
||||
func (this Slice) GetInt(key int, err ...*Error) int {
|
||||
v := ObjToInt((this)[key], err...)
|
||||
// GetInt 获取Int
|
||||
func (that Slice) GetInt(key int, err ...*Error) int {
|
||||
v := ObjToInt((that)[key], err...)
|
||||
return v
|
||||
}
|
||||
|
||||
//获取Int
|
||||
func (this Slice) GetInt64(key int, err ...*Error) int64 {
|
||||
v := ObjToInt64((this)[key], err...)
|
||||
// GetInt64 获取Int
|
||||
func (that Slice) GetInt64(key int, err ...*Error) int64 {
|
||||
v := ObjToInt64((that)[key], err...)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
//获取向上取整Int64
|
||||
func (this Slice) GetCeilInt64(key int, err ...*Error) int64 {
|
||||
v := ObjToCeilInt64((this)[key], err...)
|
||||
// GetCeilInt64 获取向上取整Int64
|
||||
func (that Slice) GetCeilInt64(key int, err ...*Error) int64 {
|
||||
v := ObjToCeilInt64((that)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取向上取整Int
|
||||
func (this Slice) GetCeilInt(key int, err ...*Error) int {
|
||||
v := ObjToCeilInt((this)[key], err...)
|
||||
// GetCeilInt 获取向上取整Int
|
||||
func (that Slice) GetCeilInt(key int, err ...*Error) int {
|
||||
v := ObjToCeilInt((that)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取向上取整float64
|
||||
func (this Slice) GetCeilFloat64(key int, err ...*Error) float64 {
|
||||
v := ObjToCeilFloat64((this)[key], err...)
|
||||
// GetCeilFloat64 获取向上取整float64
|
||||
func (that Slice) GetCeilFloat64(key int, err ...*Error) float64 {
|
||||
v := ObjToCeilFloat64((that)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取Float64
|
||||
func (this Slice) GetFloat64(key int, err ...*Error) float64 {
|
||||
v := ObjToFloat64((this)[key], err...)
|
||||
// GetFloat64 获取Float64
|
||||
func (that Slice) GetFloat64(key int, err ...*Error) float64 {
|
||||
v := ObjToFloat64((that)[key], err...)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (this Slice) GetSlice(key int, err ...*Error) Slice {
|
||||
v := ObjToSlice((this)[key], err...)
|
||||
func (that Slice) GetSlice(key int, err ...*Error) Slice {
|
||||
v := ObjToSlice((that)[key], err...)
|
||||
return v
|
||||
}
|
||||
|
||||
func (this Slice) GetBool(key int, err ...*Error) bool {
|
||||
func (that Slice) GetBool(key int, err ...*Error) bool {
|
||||
|
||||
//var v Slice
|
||||
v := ObjToBool((this)[key], err...)
|
||||
v := ObjToBool((that)[key], err...)
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
func (this Slice) GetMap(key int, err ...*Error) Map {
|
||||
func (that Slice) GetMap(key int, err ...*Error) Map {
|
||||
//var v Map
|
||||
v := ObjToMap((this)[key], err...)
|
||||
v := ObjToMap((that)[key], err...)
|
||||
return v
|
||||
}
|
||||
|
||||
func (this Slice) Get(key int, err ...*Error) interface{} {
|
||||
func (that Slice) Get(key int, err ...*Error) interface{} {
|
||||
|
||||
if key < len(this) {
|
||||
return this[key]
|
||||
if key < len(that) {
|
||||
return that[key]
|
||||
}
|
||||
e := errors.New("没有存储key及对应的数据")
|
||||
if len(err) != 0 {
|
||||
@@ -87,10 +87,10 @@ func (this Slice) Get(key int, err ...*Error) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this Slice) Put(key int, value interface{}) {
|
||||
this[key] = value
|
||||
func (that Slice) Put(key int, value interface{}) {
|
||||
that[key] = value
|
||||
}
|
||||
|
||||
func (this Slice) ToJsonString() string {
|
||||
return ObjToStr(this)
|
||||
func (that Slice) ToJsonString() string {
|
||||
return ObjToStr(that)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user