update log add date utils
This commit is contained in:
parent
a5e6669573
commit
1c7c9a54c8
24
date/formater.go
Normal file
24
date/formater.go
Normal file
@ -0,0 +1,24 @@
|
||||
package date
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
YYYYMMDDHHmmSS = "2006-01-02 15:04:05"
|
||||
)
|
||||
|
||||
func Formater(formater string) string {
|
||||
r := ""
|
||||
for _, v := range formater {
|
||||
s := fmt.Sprintf("%c", v)
|
||||
switch s {
|
||||
case "y", "Y":
|
||||
r += s
|
||||
|
||||
case "-", " ":
|
||||
r += s
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
11
date/formater_test.go
Normal file
11
date/formater_test.go
Normal file
@ -0,0 +1,11 @@
|
||||
package date
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ehlxr/go-utils/log"
|
||||
)
|
||||
|
||||
func TestDateFormater(t *testing.T) {
|
||||
log.Infof("now tims is %s", Formater("yyyy-MM-dd HH:mm:ss"))
|
||||
}
|
@ -16,7 +16,7 @@ type (
|
||||
|
||||
var (
|
||||
mylog *logrus.Logger
|
||||
fn bool
|
||||
fn bool //whether show file line
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -36,6 +36,7 @@ func init() {
|
||||
fn = true
|
||||
}
|
||||
|
||||
// whether show file line
|
||||
func SetFn(val bool) {
|
||||
fn = val
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user