From dca679edcbe1b52e7974778f4c6cbf8c3fa33c17 Mon Sep 17 00:00:00 2001 From: Jonathan Kamens Date: Tue, 28 Jul 2015 04:38:41 -0400 Subject: [PATCH] BUG: Logbook 0.10.0 requires explicit handler As of logbook 0.10.0, logbook no longer installs a default handler, which means that if the application doesn't install one, log messages disappear into the ether. Therefore, all of our scripts with `__main__` endpoints need to push a `logbook.StderrHandler` if they're not already pushing some other handler. --- scripts/generate_new_sample_saved_state.py | 2 ++ scripts/run_algo.py | 2 ++ zipline/examples/dual_ema_talib.py | 2 ++ zipline/examples/pairtrade.py | 2 ++ zipline/examples/quantopian_buy_apple.py | 2 ++ 5 files changed, 10 insertions(+) diff --git a/scripts/generate_new_sample_saved_state.py b/scripts/generate_new_sample_saved_state.py index d9165a0c..1119851e 100644 --- a/scripts/generate_new_sample_saved_state.py +++ b/scripts/generate_new_sample_saved_state.py @@ -14,6 +14,7 @@ # limitations under the License. import datetime +import logbook import os import pickle import pytz @@ -136,6 +137,7 @@ def generate_object_state(cls, initargs): if __name__ == "__main__": + logbook.StderrHandler().push_application() for args in argument_list: generate_object_state(*args) diff --git a/scripts/run_algo.py b/scripts/run_algo.py index 22bbeb0b..dc3cbcee 100755 --- a/scripts/run_algo.py +++ b/scripts/run_algo.py @@ -14,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logbook import sys from zipline.utils import parse_args, run_pipeline if __name__ == "__main__": + logbook.StderrHandler().push_application() parsed = parse_args(sys.argv[1:]) run_pipeline(print_algo=True, **parsed) sys.exit(0) diff --git a/zipline/examples/dual_ema_talib.py b/zipline/examples/dual_ema_talib.py index 96a0283d..d13c97b2 100644 --- a/zipline/examples/dual_ema_talib.py +++ b/zipline/examples/dual_ema_talib.py @@ -66,12 +66,14 @@ def handle_data(context, data): if __name__ == '__main__': from datetime import datetime + import logbook import matplotlib.pyplot as plt import pytz from zipline.algorithm import TradingAlgorithm from zipline.api import order, record, symbol from zipline.utils.factory import load_from_yahoo + logbook.StderrHandler().push_application() start = datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc) end = datetime(2014, 11, 1, 0, 0, 0, 0, pytz.utc) data = load_from_yahoo(stocks=['AAPL'], indexes={}, start=start, diff --git a/zipline/examples/pairtrade.py b/zipline/examples/pairtrade.py index ffb37d53..f78a20b4 100755 --- a/zipline/examples/pairtrade.py +++ b/zipline/examples/pairtrade.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logbook import matplotlib.pyplot as plt import numpy as np import statsmodels.api as sm @@ -116,6 +117,7 @@ class Pairtrade(TradingAlgorithm): self.order(self.PEP, -1 * pep_amount) if __name__ == '__main__': + logbook.StderrHandler().push_application() start = datetime(2000, 1, 1, 0, 0, 0, 0, pytz.utc) end = datetime(2002, 1, 1, 0, 0, 0, 0, pytz.utc) data = load_from_yahoo(stocks=['PEP', 'KO'], indexes={}, diff --git a/zipline/examples/quantopian_buy_apple.py b/zipline/examples/quantopian_buy_apple.py index f07b24ca..74624c97 100644 --- a/zipline/examples/quantopian_buy_apple.py +++ b/zipline/examples/quantopian_buy_apple.py @@ -14,6 +14,7 @@ # limitations under the License. from datetime import datetime +import logbook import pytz from zipline import TradingAlgorithm @@ -34,6 +35,7 @@ def handle_date(context, data): if __name__ == '__main__': import pylab as pl + logbook.StderrHandler().push_application() start = datetime(2008, 1, 1, 0, 0, 0, 0, pytz.utc) end = datetime(2010, 1, 1, 0, 0, 0, 0, pytz.utc) data = load_from_yahoo(stocks=['AAPL'], indexes={}, start=start,