Skip to content

Commit

Permalink
Add command line flag for changing the loglevel.
Browse files Browse the repository at this point in the history
Also reduced the checking message to debug level
  • Loading branch information
mikemill committed Jul 29, 2017
1 parent c22d444 commit 25c49e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rq_retry_scheduler/cli/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def get_arguments(args=None):
'-i', '--interval', help='Scheduler polling interval (in seconds)',
default=10.0, type=float)

parser.add_argument('--loglevel', help="Logging level",
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR',
'CRITICAL'])

return parser.parse_args(args)


Expand All @@ -57,7 +61,7 @@ def get_redis(args):

def setup_logging(args):
logger = logging.getLogger('rq:retryscheduler:scheduler')
logger.setLevel('INFO')
logger.setLevel(vars(args).get('loglevel', 'INFO'))
formatter = logging.Formatter(fmt='%(asctime)s %(message)s',
datefmt='%H:%M:%S')
handler = ColorizingStreamHandler()
Expand Down
2 changes: 1 addition & 1 deletion rq_retry_scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def is_repeat(self, job):
return 'interval' in job.meta

def enqueue_jobs(self):
self.log.info('Checking for scheduled jobs...')
self.log.debug('Checking for scheduled jobs...')

jobs = self.get_jobs_to_queue(to_unix(self.current_time()))

Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def test_setup_logging():
assert logger.getEffectiveLevel() == logging.INFO
assert len(logger.handlers) > 0

args = Namespace(loglevel='ERROR')
logger = scheduler.setup_logging(args)

assert logger.getEffectiveLevel() == logging.ERROR


def test_main(mock):
args = Namespace(url='redis://localhost/15', interval=5, burst=False)
Expand Down

0 comments on commit 25c49e1

Please sign in to comment.