Skip to content

Commit

Permalink
Add coloured timestamp + more flexible timestamp params
Browse files Browse the repository at this point in the history
  • Loading branch information
lucagrulla committed Mar 3, 2017
1 parent 3d9758b commit 875e6be
Show file tree
Hide file tree
Showing 340 changed files with 13,175 additions and 19,197 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ On Mac:

## TODOs:

* fix bug for long polling once events are finished(currently we print again a last chunk of alerts)
* ~~fix bug for long polling once events are finished(currently we print again a last chunk of alerts)~~
* ~~add an optionl end date for time window~~
* allow more flexible startTime format(no seconds means 00, no minutes means 00:00)
* add coloured output
Expand Down
4 changes: 2 additions & 2 deletions cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
// "github.com/fatih/color"
"github.com/fatih/color"
)

func cwClient() *cloudwatchlogs.CloudWatchLogs {
Expand Down Expand Up @@ -65,7 +65,7 @@ func Tail(logGroupName *string, follow *bool, startTime *string, endTime *string
idx := sort.SearchStrings(ids, *event.EventId)
if ids == nil || (idx == len(ids) || ids[idx] != *event.EventId) {
d := timeutil.FormatTimestamp(eventTimestamp)
fmt.Printf("%s - %s\n", d, *event.Message)
fmt.Printf("%s - %s\n", color.GreenString(d), *event.Message)
}
ids = append(ids, *event.EventId)
}
Expand Down
18 changes: 9 additions & 9 deletions lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"memo": "a33be850d9c3a86dbaeffcb264a5735b451d1c3a195fb6d08a7554ede46a942d",
"memo": "4c6dadf36a8afd6bbcf9a79c3971a18d9bd33879cea686e64caa1d35c80b9b7d",
"projects": [
{
"name": "github.com/alecthomas/template",
Expand All @@ -20,7 +20,7 @@
{
"name": "github.com/aws/aws-sdk-go",
"branch": "master",
"revision": "ab16e115479efb695e122bc4bb3e0ad52419d1ba",
"revision": "78568b07950e5e7948496878fe99b9436add41d4",
"packages": [
"aws",
"aws/session",
Expand All @@ -37,8 +37,8 @@
},
{
"name": "github.com/go-ini/ini",
"version": "v1.24.0",
"revision": "e3c2d47c61e5333f9aa2974695dd94396eb69c75",
"version": "v1.25.2",
"revision": "74bdc99692c3408cb103221e38675ce8fda0a718",
"packages": [
"."
]
Expand All @@ -61,24 +61,24 @@
},
{
"name": "github.com/mattn/go-isatty",
"version": "v0.0.1",
"revision": "3a115632dcd687f9c8cd01679c83a06a0e21c1f3",
"branch": "master",
"revision": "dda3de49cbfcec471bd7a70e6cc01fcc3ff90109",
"packages": [
"."
]
},
{
"name": "golang.org/x/sys",
"branch": "master",
"revision": "e4594059fe4cde2daf423055a596c2cd1e6c9adf",
"revision": "76cc09b634294339fa19ec41b5f2a0b3932cea8b",
"packages": [
"unix"
]
},
{
"name": "gopkg.in/alecthomas/kingpin.v2",
"version": "v2.2.3",
"revision": "e9044be3ab2a8e11d4e1f418d12f0790d57e8d70",
"version": "v2.0.0",
"revision": "ec97771e49d7b6a53739abb87bec6ffe1ea29074",
"packages": [
"."
]
Expand Down
35 changes: 28 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
// "fmt"
"strings"
"time"

"github.com/lucagrulla/cw/cloudwatch"
Expand All @@ -16,21 +16,42 @@ var (
tailCommand = kingpin.Command("tail", "Tail a log group")
follow = tailCommand.Flag("follow", "Don't stop when the end of stream is reached").Short('f').Default("false").Bool()
logGroupName = tailCommand.Arg("group", "The log group name").Required().String()
startTime = tailCommand.Arg("start", "The tailing start time in the format 2017-02-27T09:00:00").Default(time.Now().Add(-20 * time.Second).Format(timeutil.TimeFormat)).String()
endTime = tailCommand.Arg("end", "The tailing end time in the format 2017-02-27T09:00:00").String()
startTime = tailCommand.Arg("start", "The tailing start time in the format 2017-02-27[T09:00:[00]]").Default(time.Now().Add(-30 * time.Second).Format(timeutil.TimeFormat)).String()
endTime = tailCommand.Arg("end", "The tailing end time in the format 2017-02-27[T09:00:[00]]").String()
streamName = tailCommand.Arg("stream", "an opotional stream name").String()
)

func timestampShortcut(timeStamp *string) string {
if *timeStamp == "" {
return *timeStamp
}
tokens := strings.Split(*timeStamp, "T")
if len(tokens) == 1 {
return strings.Join([]string{*timeStamp, "00:00:00"}, "T")
} else {
time := strings.Split(tokens[1], ":")
switch len(time) {
case 1:
return strings.Join([]string{*timeStamp, "00:00"}, ":")
case 2:
return strings.Join([]string{*timeStamp, "00"}, ":")
default:
return *timeStamp
}

}
}

func main() {
kingpin.Version("0.1.0")
kingpin.Version("0.1.2")
command := kingpin.Parse()

switch command {
case "ls":
cloudwatch.Ls()
case "tail":
// fmt.Println(strings.Split(*startTime, "T"))
// fmt.Println(strings.SplitAfter(*startTime, "T"))
cloudwatch.Tail(logGroupName, follow, startTime, endTime, streamName)
st := timestampShortcut(startTime)
et := timestampShortcut(endTime)
cloudwatch.Tail(logGroupName, follow, &st, &et, streamName)
}
}
7 changes: 6 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"github.com/aws/aws-sdk-go": {
"branch": "master"
},
"gopkg.in/alecthomas/kingpin.v2": {}
"github.com/fatih/color": {
"branch": "master"
},
"gopkg.in/alecthomas/kingpin.v2": {
"version": "2"
}
}
}
76 changes: 76 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions vendor/github.com/aws/aws-sdk-go/aws/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 875e6be

Please sign in to comment.