From d347e0adc88c29470b1376b69e1b39b2ea312934 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Sat, 10 Aug 2013 18:04:37 +0200 Subject: [PATCH] Documentation and example of the Python API --- ChangeLog | 4 ++++ README | 13 +++++++++++++ examples/example1.py | 24 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 examples/example1.py diff --git a/ChangeLog b/ChangeLog index 01eeda5..e76535d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-08-10 18:04:37 +0200 Julien Palard + + * Documentation and example of the Python API + 2013-08-10 17:45:24 +0200 Julien Palard * Documentation and example of the C API diff --git a/README b/README index c948eea..d37929b 100644 --- a/README +++ b/README @@ -59,6 +59,19 @@ C API : You can find an example of using the C API in examples/example1.c +Python API : + logtop module exposes a logtop class containing : + logtop.__init__(history_size) to build a new logtop keeping + at most history_size lines. + logtop.feed(line) to feed a new line in logtop. + logtop.get(qte_of_elements) to get the top qte_of_elements lines. + logtop.qte_of_elements() to get the current total number of lines. + logtop.timespan() to get the duration from the oldest line to now. + + timespan may be less than the runtime, as logtop drop old lines, + to keep, at most, history_size lines, given in the constructor of + the logtop class. + About libavl: The libavl used here is the Ben Pfaff's one, statically build with logtop, as Ben want it to be (see INSTALL file and here : diff --git a/examples/example1.py b/examples/example1.py new file mode 100644 index 0000000..a3d6ba2 --- /dev/null +++ b/examples/example1.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +import pprint +import sys +sys.path.append('..') + +from logtop import logtop + + +""" + +This example show a complete usage of the python API, +It can be used like this : + +$ make python-module +$ cat /etc/passwd | cut -d: -f7 | python example1.py + +""" + +l = logtop(10000) +for line in sys.stdin: + l.feed(line) + +pprint.pprint(l.get(10))