Skip to content

Commit

Permalink
Merge pull request #55 from alpacahq/logLevelChanges
Browse files Browse the repository at this point in the history
Log level changes
  • Loading branch information
ttt733 authored Nov 29, 2018
2 parents 4efc5bb + c7b1edb commit 881a816
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pylivetrader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pylivetrader/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
)
from pylivetrader.statestore import StateStore

from logbook import Logger
from logbook import Logger, lookup_level


log = Logger('Algorithm')
Expand All @@ -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')
Expand Down

0 comments on commit 881a816

Please sign in to comment.