Giter VIP home page Giter VIP logo

loggrep's Introduction

loggrep

Grep, but for log files of various shapes and sizes

This project was created in slightly more than an evening with the intention that I'll add more log formats to it as I go along and feel like they would be useful. There's no guarantee I'll actually do that though.

Installation

Download the latest release from the releases page and add it somewhere on your path (e.g. ~/.bin/local).

Windows users will currently need to build from source using cargo build --release, sorry!

There is also a docker image available on Docker Hub

Usage

Grep, but for log files of various shapes and sizes

Usage: loggrep [OPTIONS] [FIELD] [PATTERN]

Arguments:
  [FIELD]    Field to filter on
  [PATTERN]  Pattern to filter the field on

Options:
  -f, --format <FORMAT>  Specify the expected format of the logs
  -i, --ignore-case      Ignore case
  -v, --invert-match     Invert the sense of matching, to select non-matching lines
  -F, --fixed            Set the pattern to compare fixed strings rather than a regex
  -h, --help             Print help
  -V, --version          Print version

For example, for filter for nginx requests from 66.249.65.159, you could do:

cat logfile.txt | loggrep -F remote_addr '66.249.65.159'

Or to filter for GET requests:

cat logfile.txt | loggrep request '^GET'

With docker:

cat logfile.txt | docker run -i jamoyjamie/loggrep:<version> request '^GET'

Supported Formats

nginx

Format identifier: nginx

The default format of nginx logs. The following fields map to the nginx variables of the same name.

Fields:

  • remote_addr
  • remote_user
  • request
  • status
  • body_bytes_sent
  • http_referer
  • user_agent

syslog-bsd

Format identifier: syslog-bsd

Original BSD syslog format defined in RFC-3164

Fields:

  • priority
  • timestamp
  • hostname
  • message

Python

Format identifier: python

Default log format for Python as per the source

Fields:

  • levelname
  • name
  • message

PostgreSQL

Format identifier: postgresql

Default PostgreSQL database log format as per the documentation

  • timestamp
  • pid
  • user
  • database
  • type
  • message

update-alternatives

Format identifier: update-alternatives

Simple format for the update-alternatives log in /var/log/alternatives.log.

Fields:

  • timestamp
  • message

dpkg

Format identifier: dpkg

Format for dpkg logs in /var/log/dpkg.log as per the man page. Note that this log format has three different forms which makes it tricky to parse. Due to internal limitations, currently some fields need to be repeated with a numeric on the end.

Fields:

  • timestamp
  • type
  • command
  • state
  • pkg
  • installed_version
  • action
  • pkg_2
  • installed_version_2
  • available_version
  • filename
  • decision

Common Log Format (CLF)/NCSA/Combined Log Format (also CLF)

Format identifier: clf

Common Log Format as per Wikipedia and Microsoft also known as NCSA HTTPd used by web servers. This also implements to Combined Log Format as per the httpd docs which is the same but with some additional fields.

Fields:

  • host
  • ident
  • auth_user
  • timestamp
  • request
  • status
  • bytes
  • referer (combined log format)
  • user_agent (combined log format)

TODO

loggrep's People

Contributors

jamjar00 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.