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