Giter Club home page Giter Club logo

liblf's Introduction

liblf: A parser for the syntax used by Apache's LogFormat Directive

The LogFormat directive provides a printf-like syntax for specifying user-defined custom formats for log messages. It's intended for logs about HTTP traffic, and includes formatting for IP addresses, response status, and other relevant things.

There's an EBNF grammar for the syntax. Apache's documentation is the authoritative reference for the various format directives.

What would I use it for?

Maybe you're writing a daemon that serves requests (not necessarily HTTP) and you'd like to give your users a familiar-feeling syntax for configuring what to log. Or perhaps you're writing a tool to convert Apache configurations to another system.

You can disable the directives you don't need, and add custom ones.

How do I use it?

This library aims to provide a complete implementation, presenting an API independent of any particular source for data, and of any particular output. The entry point is lf_parse(), which calls various callbacks as it parses each part of the format string. See <lf.h> for the API.

  • As a parser: Have your callbacks store the data, and act on it later.
  • As an interpreter: Parse log format strings whilst serving a request, and have your callbacks output the relevant items immediately.
  • As a compiler: Parse log format strings ahead of time, and output generated code.

There's an example program which just prints out directives as they come. You get pretty decent error messages:

; lfdump '%{}e %v %h %l %u %t \"%r\" %>s %b %{user-agent}i'
error: Empty name
at 1: '%{}e %v %h %l %u %t \"%r\" %>s %b %{user-agent}i'
--------^^

Related projects:

Clone with submodules (contains required .mk files):

; git clone --recursive https://github.com/katef/liblf.git

To build and install:

; pmake -r install

You can override a few things:

; CC=clang PREFIX=$HOME pmake -r install

Building depends on:

  • Any BSD make. This includes OpenBSD, FreeBSD and NetBSD make(1) and sjg's portable bmake (also packaged as pmake).

  • A C compiler. Any should do, but GCC and clang are best supported.

  • ar, ld, and a bunch of other stuff you probably already have.

Fuzzing depends on:

; pmake -r CC=gcc DEBUG=1 && pmake VERBOSE=1 -r fuzz

Ideas, comments or bugs: [email protected]

liblf's People

Contributors

katef avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.