From 1c7c9a54c8bbdcf60529d5596c8f6d94c54c1d72 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Tue, 11 Jul 2017 17:33:03 +0800 Subject: [PATCH] update log add date utils --- date/formater.go | 24 ++++++++++++++++++++++++ date/formater_test.go | 11 +++++++++++ log/log.go | 3 ++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 date/formater.go create mode 100644 date/formater_test.go diff --git a/date/formater.go b/date/formater.go new file mode 100644 index 0000000..231047c --- /dev/null +++ b/date/formater.go @@ -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 +} diff --git a/date/formater_test.go b/date/formater_test.go new file mode 100644 index 0000000..da5c7a9 --- /dev/null +++ b/date/formater_test.go @@ -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")) +} diff --git a/log/log.go b/log/log.go index 027c591..3aafebe 100644 --- a/log/log.go +++ b/log/log.go @@ -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 }