]>
gitweb.michael.orlitzky.com - djbdns-logparse.git/blob - bin/djbdns-logparse
3 Convert tinydns and dnscache logs to human-readable form
5 # Avoid clobbering the top-level exit() built-in.
8 from signal
import signal
, SIGINT
9 from argparse
import ArgumentParser
, FileType
10 from djbdns
.io
import parse_logfile
12 # Create an argument parser using the file's docsctring as its
14 parser
= ArgumentParser(description
= __doc__
)
16 # Parse zero or more positional arguments into a list of
17 # "logfiles". If none are given, read from stdin instead.
18 parser
.add_argument("logfiles",
23 help="djbdns logfile to process (default: stdin)")
25 # Warning: argparse automatically opens its file arguments here,
26 # and they only get closed when the program terminates. There's no
27 # real benefit to closing them one-at-a-time after calling
28 # parse_logfile(), because the "scarce" resource of open file
29 # descriptors gets consumed immediately, before any processing has
30 # happened. In other words, if you're going to run out of file
31 # descriptors, it's going to happen right now.
33 # So anyway, don't run this on several million logfiles.
34 args
= parser
.parse_args()
36 # Install a SIGINT handler so thst we don't spit out a stack trace when
37 # the user accidentally starts the program with no arguments and then
38 # hits Ctrl-C to kill it.
39 signal(SIGINT
, lambda s
,f
: sys
.exit(0))
41 for f
in args
.logfiles
: