|
@@ -181,6 +181,10 @@ Example:
|
|
|
|
|
|
`<Timezone:+0800CST>` will specified the timezone to CST(+0800) for output.
|
|
|
|
|
|
+### External Tags
|
|
|
+
|
|
|
+By Using TimeFormatterEx, you can append your custom tags.
|
|
|
+
|
|
|
### Using This Package In Go
|
|
|
|
|
|
*Installation*
|
|
@@ -191,6 +195,8 @@ go get git.swzry.com/zry/YAGTF
|
|
|
|
|
|
*Coding*
|
|
|
|
|
|
+With Basic Formatter
|
|
|
+
|
|
|
```
|
|
|
package main
|
|
|
|
|
@@ -201,10 +207,65 @@ import (
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
- tf := timefmt.NewTimeFormatter("!<y>-<mon>-<d> <h24>:<min>:<s> <tz> <tzA>", false)
|
|
|
+ tf := timefmt.NewDefaultTimeFormatter("!<y>-<mon>-<d> <h24>:<min>:<s> <tz> <tzA>", false)
|
|
|
+ fmt.Println(tf.Format(time.Now()))
|
|
|
+ tf = timefmt.NewDefaultTimeFormatter("!<UTC><y>-<mon>-<d> <h24>:<min>:<s> <tz> <tzA>", false)
|
|
|
+ fmt.Println(tf.Format(time.Now()))
|
|
|
+ tf = timefmt.NewDefaultTimeFormatter("!<Timezone:+0900JST><y>-<mon>-<d> <h24>:<min>:<s><br><tz> <tzA>", true)
|
|
|
+ fmt.Println(tf.Format(time.Now()))
|
|
|
+ tf = timefmt.NewDefaultTimeFormatter("!<Timezone:+0900JST><y>-<mon>-<d> <h24>:<min>:<s><br><tz> <tzA>", false)
|
|
|
+ fmt.Println(tf.Format(time.Now()))
|
|
|
+ tf = timefmt.NewDefaultTimeFormatter("yyyy-MM-dd HH:mm:ss z Z", false)
|
|
|
+ fmt.Println(tf.Format(time.Now()))
|
|
|
+ tf = timefmt.NewDefaultTimeFormatter("!yyyy-MM-dd HH:mm:ss z Z", false)
|
|
|
+ fmt.Println(tf.Format(time.Now()))
|
|
|
+ tf = timefmt.NewDefaultTimeFormatter("!!yyyy-MM-dd HH:mm:ss z Z", false)
|
|
|
fmt.Println(tf.Format(time.Now()))
|
|
|
}
|
|
|
+```
|
|
|
|
|
|
+With TimeFormatterEx:
|
|
|
+```
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "git.swzry.com/zry/YAGTF/yagtf/tfelem"
|
|
|
+ "git.swzry.com/zry/YAGTF/yagtf/timefmt"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ printer := timefmt.NewTimePrinterEx()
|
|
|
+ parser := timefmt.NewFormatParser(true)
|
|
|
+ parser.AddExDataTag("level", func() timefmt.TimeElementEx {
|
|
|
+ return tfelem.NewExDataElement(4, "level")
|
|
|
+ })
|
|
|
+ parser.AddExDataTag("app", func() timefmt.TimeElementEx {
|
|
|
+ return tfelem.NewExDataElement(64, "app")
|
|
|
+ })
|
|
|
+ parser.AddExDataTag("msg", func() timefmt.TimeElementEx {
|
|
|
+ return tfelem.NewExDataElement(2048, "msg")
|
|
|
+ })
|
|
|
+ tf := timefmt.NewTimeFormatterEx(printer, parser, false)
|
|
|
+ tf.ParseFormat("![<y>-<mon>-<d> <h24>:<min>:<s> <tz> <tzA>] <lt><level><gt> <app> : <msg>")
|
|
|
+ logtest(tf, "INFO", "test1.app", "hello, world")
|
|
|
+ logtest(tf, "WARN", "test2.app", "hello, gensokyo")
|
|
|
+ logtest(tf, "INFO", "test3.app", "the quick brown fox jumps over a lazy dog.")
|
|
|
+ logtest(tf, "INFO", "test4.app", "Unicode Test With Emoji 1:☁⚡🪁🗝️👨, 👨💡, 📍✔️. ⛪❌📍. ☁⚡, ☁⚡⛪, ⛪🔥, 🏢️📍✔️.")
|
|
|
+ logtest(tf, "INFO", "test5.app", "Unicode Test With Emoji 2:🇨🇳, 1980 < 📅 < 2015, 👶✖️1 = ✔️; 📅 > 2015, 👶✖️2 = ✔️.")
|
|
|
+ logtest(tf, "INFO", "test6.app", "Unicode Test With Emoji 3:👦✂🔌, ⚡👦, 🚑🏥, 😷💉, 😷😱, 👦☠️. 👵🏽😭, 💴⚰️, 👮⚰️❌, 🔥💀->⚱️✔️.")
|
|
|
+ logtest(tf, "INFO", "test7.app", "Unicode Test With Emoji 4:👦🚬🚄, 👮🚭, 💴, 👦👿, 👦💣💥🚔, 👮😱, 👮🔫👦, 👦☠️.")
|
|
|
+ logtest(tf, "INFO", "test8.app", "Unicode Test With Chinese and Emoji: 魔理沙偷走了重要的📚, 帕秋莉👿.")
|
|
|
+}
|
|
|
+
|
|
|
+func logtest(tf *timefmt.TimeFormatterEx, level string, app string, msg string) {
|
|
|
+ exdata := make(map[string]string)
|
|
|
+ exdata["level"] = level
|
|
|
+ exdata["app"] = app
|
|
|
+ exdata["msg"] = msg
|
|
|
+ fmt.Println(tf.Format(time.Now(), exdata))
|
|
|
+}
|
|
|
```
|
|
|
|
|
|
## 中文文档
|