Skip to content

Commit

Permalink
Refactor logging and add log level argument
Browse files Browse the repository at this point in the history
Relocated logger configuration to respond to command line log level argument and refactored imports for readability. Added '--loglevel' argument to specify the logging level, defaulting to 'INFO'. This change enhances flexibility and control over the logging behavior based on user preferences.
  • Loading branch information
L1ghtn1ng committed Oct 19, 2024
1 parent ac6e78a commit 577ab6a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions dnsrecon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import os
import sqlite3
import sys
from argparse import ArgumentParser, RawTextHelpFormatter, ArgumentError
from argparse import ArgumentError, ArgumentParser, RawTextHelpFormatter
from concurrent import futures
from pathlib import Path
from random import SystemRandom
Expand Down Expand Up @@ -1502,9 +1502,6 @@ def ds_zone_walk(res, domain, lifetime):


def main():
logger.remove()
logger.add(sys.stderr, format='{time} {level} {message}', level='DEBUG')
logger.add('~/.config/dnsrecon/dnsrecon.log', rotation='100 MB', compression='tar.gz')
#
# Option Variables
#
Expand Down Expand Up @@ -1607,6 +1604,15 @@ def main():
default=3.0,
help='Time to wait for a server to respond to a query. default is 3.0',
)

parser.add_argument(
'--loglevel',
type=str,
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
default='INFO',
help='Log level to use. default is INFO',
)

parser.add_argument(
'--tcp',
dest='tcp',
Expand Down Expand Up @@ -1665,6 +1671,9 @@ def main():
zonewalk: Perform a DNSSEC zone walk using NSEC records.""",
)
arguments = parser.parse_args()
logger.remove()
logger.add(sys.stderr, format='{time} {level} {message}', level=arguments.loglevel)
logger.add('~/.config/dnsrecon/dnsrecon.log', rotation='100 MB', compression='tar.gz')

except SystemExit:
# Handle exit() from passing --help
Expand Down

0 comments on commit 577ab6a

Please sign in to comment.