From 3b48149ba7aeac653fbe5f9ca62707c6f03a4640 Mon Sep 17 00:00:00 2001 From: hahwul Date: Tue, 9 Feb 2021 03:21:18 +0900 Subject: [PATCH] (Closed #8) Added -with-time option --- main.go | 10 ++++++---- pkg/gee/gee.go | 3 +++ pkg/gee/time.go | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 pkg/gee/time.go diff --git a/main.go b/main.go index 7013079..560c856 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ func main() { appendOption := flag.Bool("append", false, "Append mode for files") chunkedLineOption := flag.Int("chunked", 0, "Chuked files from line (e.g output / output_1 / output_2)") withLineOption := flag.Bool("with-line", false, "With line number") + withTimeOption := flag.Bool("with-time", false, "With timestamp") flag.Parse() // Show version @@ -35,10 +36,11 @@ func main() { // Set Options options := model.Options{ - Files: files, - Append: *appendOption, - ChunkedLine: *chunkedLineOption, - WithLine: *withLineOption, + Files: files, + Append: *appendOption, + ChunkedLine: *chunkedLineOption, + WithLine: *withLineOption, + WithTimestamp: *withTimeOption, } // Running gee app diff --git a/pkg/gee/gee.go b/pkg/gee/gee.go index b055027..73aff29 100644 --- a/pkg/gee/gee.go +++ b/pkg/gee/gee.go @@ -38,6 +38,9 @@ func Gee(options model.Options) { if options.WithLine { l = "[" + strconv.Itoa(stdLine) + "] " + l } + if options.WithTimestamp { + l = "[" + GetNowTime() + "] " + l + } line = l diff --git a/pkg/gee/time.go b/pkg/gee/time.go new file mode 100644 index 0000000..bf665f2 --- /dev/null +++ b/pkg/gee/time.go @@ -0,0 +1,14 @@ +package gee + +import ( + "fmt" + "time" +) + +// GetNowTime is Get time string now +func GetNowTime() string { + now := time.Now() + sec := now.Unix() + rtn := fmt.Sprintf("%v", time.Unix(sec, 0)) + return rtn +}