diff --git a/README.md b/README.md new file mode 100644 index 0000000..e440cf9 --- /dev/null +++ b/README.md @@ -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. diff --git a/main.go b/main.go index 2291efd..0954054 100644 --- a/main.go +++ b/main.go @@ -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") @@ -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 { @@ -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, diff --git a/scripts/release.sh b/scripts/release.sh index 2c950a1..5cc6dc7 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -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}