diff --git a/pylivetrader/__main__.py b/pylivetrader/__main__.py index 1366a0a..caefcf4 100644 --- a/pylivetrader/__main__.py +++ b/pylivetrader/__main__.py @@ -74,6 +74,14 @@ def algo_parameters(f): type=bool, show_default=True, help='True to continue running in general exception'), + click.option( + '-l', '--log-level', + type=click.Choice( + {'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'} + ), + default='INFO', + show_default=True, + help='The minimum level of log to be written.'), click.argument('algofile', nargs=-1), ] for opt in opts: @@ -89,7 +97,8 @@ def process_algo_params( backend_config, data_frequency, statefile, - retry): + retry, + log_level): if len(algofile) > 0: algofile = algofile[0] elif file: @@ -116,6 +125,7 @@ def process_algo_params( data_frequency=data_frequency, algoname=extract_filename(algofile), statefile=statefile, + log_level=log_level, **functions, ) ctx.algorithm = algorithm diff --git a/pylivetrader/algorithm.py b/pylivetrader/algorithm.py index 96632ae..14b75ee 100644 --- a/pylivetrader/algorithm.py +++ b/pylivetrader/algorithm.py @@ -83,7 +83,7 @@ ) from pylivetrader.statestore import StateStore -from logbook import Logger +from logbook import Logger, lookup_level log = Logger('Algorithm') @@ -104,7 +104,9 @@ def __init__(self, *args, **kwargs): initialize: initialize function handle_data: handle_data function before_trading_start: before_trading_start function + log_level: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL' ''' + log.level = lookup_level(kwargs.pop('log_level', 'INFO')) self._recorded_vars = {} self.data_frequency = kwargs.pop('data_frequency', 'minute')