Skip to content

Commit

Permalink
Merge pull request #2 from kamatama41/update-readme
Browse files Browse the repository at this point in the history
Add README
  • Loading branch information
kamatama41 authored Jul 14, 2019
2 parents 22197cc + ee9b037 commit 0d6eee0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# taildog

taildog is a CLI tool to query and tail Datadog logs like `tail -f`.

# Installation

You can download the executable binary from the [releases page](https://github.com/kamatama41/taildog/releases).

```console
$ latest=$(curl -s https://api.github.com/repos/kamatama41/taildog/releases/latest | jq -r ".name")
$ os=$(uname | tr '[:upper:]' '[:lower:]')
$ curl -LO https://github.com/kamatama41/taildog/releases/download/${latest}/taildog_${latest}_${os}_amd64.zip
$ unzip taildog_${latest}_${os}_amd64.zip && rm taildog_${latest}_${os}_amd64.zip
```

# Usage

Before running, you must set the two environment variables `DD_API_KEY` and `DD_APP_KEY`, which can be taken on the [Datadog APIs page](https://app.datadoghq.com/account/settings#api).

## Examples

#### Follow all logs

```console
$ taildog
```

#### Follow logs with a query

```console
$ taildog -q "service:my-app"
```

#### Query logs for a duration (without following, max 1000 logs)

```console
$ taildog -q "service:my-app" --from 2019-07-10T11:00:00Z --to 2019-07-10T11:00:05Z
```

#### Show logs with a custom format

```console
$ taildog -q "service:my-app" -f "{{.Timestamp}} {{.Message}}"
```

# Note

taildog uses the [Log Query API](https://docs.datadoghq.com/api/?lang=bash#get-a-list-of-logs) of Datadog which is rate limited, `300` per hour per organization, and taildog calls the API every 15 seconds by default (240 times per hour). So you might encounter the rate limit error when using taildog with multiple users in your organization.
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var (
"Message format of entries in Golang's template style.\n"+
"You can use any field in the \"content\" of the response of the Log Query API.\n"+
"https://docs.datadoghq.com/api/?lang=bash#get-a-list-of-logs\n")
interval = flag.Int64("i", 15000, "Interval time in milliseconds until the next attempt")
limit = flag.Int("l", 1000, "Number of logs fetched once")
interval = flag.Int("i", 15, "Interval time in seconds until the next attempt.")
limit = flag.Int("l", 1000, "Number of logs fetched at once.")
fromStr = flag.String("from", "", "Minimum timestamp for requested logs, should be an ISO-8601 string.")
toStr = flag.String("to", "", "Maximum timestamp for requested logs, should be an ISO-8601 string.")
version = flag.Bool("V", false, "Show version of taildog")
Expand Down Expand Up @@ -82,7 +82,7 @@ func main() {
}

for cfg.follow {
time.Sleep(time.Duration(*interval) * time.Millisecond)
time.Sleep(time.Duration(*interval) * time.Second)

cfg, err = showLogs(cfg)
if err != nil {
Expand All @@ -92,8 +92,6 @@ func main() {
}

func showLogs(cfg *config) (*config, error) {
log.Println(cfg.String())

reqBody := map[string]interface{}{
"query": cfg.query,
"limit": cfg.limit,
Expand Down
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ for PLATFORM in ${PLATFORMS}; do
echo "${CMD}"
eval ${CMD}

ZIP_FILENAME="${REPO}_${VERSION}_${GOOS}_${GOARCH}.zip"
ZIP_FILENAME="${REPO}_v${VERSION}_${GOOS}_${GOARCH}.zip"
CMD="zip ${ZIP_FILENAME} ${BIN_FILENAME}"
echo "${CMD}"
eval ${CMD}
Expand Down

0 comments on commit 0d6eee0

Please sign in to comment.