]> gitweb.michael.orlitzky.com - djbdns-logparse.git/blob - bin/djbdns-logparse
7808fbd99a5042a9adc31828933949325561585e
[djbdns-logparse.git] / bin / djbdns-logparse
1 #!/usr/bin/python3
2 r"""
3 Convert tinydns and dnscache logs to human-readable form
4 """
5 from argparse import ArgumentParser, FileType
6 from djbdns.io import parse_logfile
7
8 # Create an argument parser using the file's docsctring as its
9 # description.
10 parser = ArgumentParser(description = __doc__)
11
12 # Parse zero or more positional arguments into a list of
13 # "logfiles". If none are given, read from stdin instead.
14 from sys import stdin
15 parser.add_argument("logfiles",
16 metavar="LOGFILE",
17 type=FileType("r"),
18 nargs="*",
19 default=[stdin],
20 help="djbdns logfile to process (default: stdin)")
21
22 # Warning: argparse automatically opens its file arguments here,
23 # and they only get closed when the program terminates. There's no
24 # real benefit to closing them one-at-a-time after calling
25 # parse_logfile(), because the "scarce" resource of open file
26 # descriptors gets consumed immediately, before any processing has
27 # happened. In other words, if you're going to run out of file
28 # descriptors, it's going to happen right now.
29 #
30 # So anyway, don't run this on several million logfiles.
31 args = parser.parse_args()
32 for f in args.logfiles:
33 parse_logfile(f)