Skip to main content

Elastic Log CLI

CLI for streaming logs from Elasticsearch to a terminal.

Installation

Install with pip:

pip install elastic-log-cli

📝 Requires Python 3.10

Configuration

The following environment variables are used to configure the tool. For secure, easy selection of target clusters, a tool like envchain is recommended.

Where available, CLI options will override environment variables.

ELASTICSEARCH_URL

Required

URL of the Elasticsearch cluster containing logs. You can also provide an Elastic Cloud ID by prefixing with it cloud:.

ELASTICSEARCH_USERNAME

Optional

Username for the Elasticsearch cluster containing logs.

ELASTICSEARCH_PASSWORD

Optional

Password for the Elasticsearch cluster containing logs.

ELASTICSEARCH_AUTH_MODE

Optional, default value: basicauth

Specify which authentication mode you are using.

The default behaviour is basicauth, which encodes the username and password using HTTP Basic Auth.

You may also set this to apikey, in which case the API Keys should be provided as follows:

ELASTICSEARCH_USERNAME=${APIKEY_NAME}
ELASTICSEARCH_PASSWORD=${APIKEY_KEY}

Finally, if you are using Amazon OpenSearch Service with AWS Signature V4 auth, then set this to awssigv4. AWS credentials will be read from the environment and used to sign your requests.

Possible values

basicauth, apikey, awssigv4

ELASTICSEARCH_TIMEOUT

Optional, default value: 40

How long to wait on Elasticsearch requests.

ELASTICSEARCH_INDEX

Optional, default value: filebeat-*

The index to target. Globs are supported.

ELASTICSEARCH_TIMESTAMP_FIELD

Optional, default value: @timestamp

The field which denotes the timestamp in the indexed logs.

Usage

Usage: elastic-logs [OPTIONS] QUERY

  Stream logs from Elasticsearch.

  Accepts a KQL query as its only positional argument.

Options:
  -p, --page-size INTEGER RANGE  The number of logs to fetch per page  [x>=0]
  -i, --index TEXT               The index to target. Globs are supported.
                                 [default: (filebeat-*)]
  -s, --start TEXT               When to begin streaming logs from.
  -e, --end TEXT                 When to stop streaming logs. Omit to
                                 continuously stream logs until interrupted.
  --source CSV                   Source fields to retrieve, comma-separated.
                                 Default behaviour is to fetch full document.
  -t, --timestamp-field TEXT     The field which denotes the timestamp in the
                                 indexed logs.  [default: (@timestamp)]
  --version                      Show version and exit.
  --help                         Show this message and exit.

Example

elastic-logs \
    --start 2022-03-05T12:00:00 \
    --end 2022-03-05T13:00:00 \
    --source time,level,message,error \
    --index filebeat-7.16.2 \
    --timestamp-field time \
    'level:ERROR and error.code:500'

KQL support

The following KQL features are not yet supported:

  • Wildcard fields, e.g. *:value or machine.os*:windows 10
  • Prefix matching, e.g. machine.os:win*
  • Match phrase, e.g. message:"A quick brown fox"

Development

Install dependencies:

pyenv shell 3.10.x
pre-commit install  # Configure commit hooks
poetry install  # Install Python dependencies

Run tests:

poetry run inv verify

License

This project is distributed under the MIT license.

Metadata

Release files for elastic-log-cli 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for elastic-log-cli 0.2.1
File Size Uploaded Provenance Actions
elastic-log-cli-0.2.1.tar.gz 13.2 kB Without provenance Details for elastic-log-cli-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for elastic-log-cli 0.2.1
File Interpreter ABI Platform Actions
elastic_log_cli-0.2.1-py3-none-any.whl Python 3 none any Details for elastic_log_cli-0.2.1-py3-none-any.whl

Total release size: 27.5 kB

Release files / elastic-log-cli-0.2.1.tar.gz

Download URL elastic-log-cli-0.2.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a1c86e7b8cfc7426789955568188ee7e6fbc1099898b8162c6f913bd9bf94a73
BLAKE2b-256 checksum
How to use checksums
0a727873fbc983f019c3fdee53d0b8683342efd1c5a27c4ca4873d23977d30ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.8.12 Linux/5.13.0-52-generic

Release files / elastic_log_cli-0.2.1-py3-none-any.whl

Download URL elastic_log_cli-0.2.1-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11d3e587875d9d8c3b68b3e43974ce0643137b7b8e1445e9837157d5b89f0eea
BLAKE2b-256 checksum
How to use checksums
b31082e69b3a861fb38b28c4eda9ff52503e4d110a286cd505bf43c9c90aa69a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.8.12 Linux/5.13.0-52-generic

Security for elastic-log-cli 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page