Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the log level argument to the parser (-l, --log) which by default ... #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ def collate(self, collator):
self.collator = collator
return collator

def serve(self, port=None, address=None):
def serve(self, port=None, address=None, log_level='INFO'):
"""Serves the SMTP server on the given port and address."""
port = port or self.port
address = address or self.address
log.level_name = log_level

log.info('Starting SMTP server at {0}:{1}'.format(address, port))
log.info('Starting SMTP server at {0}:{1} with {2} level logging'.format(address, port, log_level))

server = InboxServer(self.collator, (address, port), None)

Expand All @@ -61,10 +62,12 @@ def serve(self, port=None, address=None):
def dispatch(self):
"""Command-line dispatch."""
parser = argparse.ArgumentParser(description='Run an Inbox server.')
log_choices = ['critical', 'error', 'warning', 'notice', 'info', 'debug']

parser.add_argument('addr', metavar='addr', type=str, help='addr to bind to')
parser.add_argument('port', metavar='port', type=int, help='port to bind to')
parser.add_argument('-a', '--addr', metavar='addr', type=str, help='addr to bind to', required=True)
parser.add_argument('-p', '--port', metavar='port', type=int, help='port to bind to', required=True)
parser.add_argument('-l', '--log', metavar='log', type=str, help='logging level (%s)' % (','.join(log_choices)), default='info', choices=log_choices)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using tabs instead of spaces here, please fix


args = parser.parse_args()

self.serve(port=args.port, address=args.addr)
self.serve(port=args.port, address=args.addr, log_level=args.log.upper())