Repository: liberapay/liberapay.com

Issue:
Payday log messages aren't visible
Came up in https://github.com/liberapay/salon/issues/41. Origin: https://github.com/liberapay/liberapay.com/pull/337.

Payday log messages aren't visible
Came up in https://github.com/liberapay/salon/issues/41. Origin: https://github.com/liberapay/liberapay.com/pull/337.



Discussion:

Resolving patch:
diff --git a/liberapay/billing/payday.py b/liberapay/billing/payday.py
--- a/liberapay/billing/payday.py
+++ b/liberapay/billing/payday.py
@@ -1,6 +1,5 @@
-from __future__ import unicode_literals
+from __future__ import print_function, unicode_literals
 
-import logging
 import os
 import os.path
 import pickle
@@ -15,7 +14,7 @@
 from liberapay.utils import group_by
 
 
-logger = logging.getLogger('liberapay.billing.payday')
+log = print
 
 
 class NoPayday(Exception):
@@ -49,18 +48,18 @@ def start(cls):
                 ), 0) + 1)
                 RETURNING id, (ts_start AT TIME ZONE 'UTC') AS ts_start
             """, back_as=dict)
-            logger.info("Starting payday #%s." % d['id'])
+            log("Starting payday #%s." % d['id'])
         except IntegrityError:  # Collision, we have a Payday already.
             d = cls.db.one("""
                 SELECT id, (ts_start AT TIME ZONE 'UTC') AS ts_start
                   FROM paydays
                  WHERE ts_end='1970-01-01T00:00:00+00'::timestamptz
             """, back_as=dict)
-            logger.info("Picking up payday #%s." % d['id'])
+            log("Picking up payday #%s." % d['id'])
 
         d['ts_start'] = d['ts_start'].replace(tzinfo=aspen.utils.utc)
 
-        logger.info("Payday started at %s." % d['ts_start'])
+        log("Payday started at %s." % d['ts_start'])
 
         payday = Payday()
         payday.__dict__.update(d)
@@ -76,7 +75,7 @@ def run(self, log_dir='', keep_log=False):
         self.db.self_check()
 
         _start = aspen.utils.utcnow()
-        logger.info("Greetings, program! It's PAYDAY!!!!")
+        log("Greetings, program! It's PAYDAY!!!!")
 
         self.shuffle(log_dir)
 
@@ -92,7 +91,7 @@ def run(self, log_dir='', keep_log=False):
         _end = aspen.utils.utcnow()
         _delta = _end - _start
         fmt_past = "Script ran for %%(age)s (%s)." % _delta
-        logger.info(aspen.utils.to_age(_start, fmt_past=fmt_past))
+        log(aspen.utils.to_age(_start, fmt_past=fmt_past))
 
     def shuffle(self, log_dir=''):
         self.transfers_filename = log_dir+'payday-%s_transfers.pickle' % self.id
@@ -370,7 +369,7 @@ def prepare(cursor, ts_start):
         $$ LANGUAGE plpgsql;
 
         """, dict(ts_start=ts_start))
-        logger.info("Prepared the DB.")
+        log("Prepared the DB.")
 
     @staticmethod
     def transfer_virtually(cursor):
@@ -400,9 +399,9 @@ def check_balances(cursor):
              LIMIT 1
         """)
         if oops:
-            logger.critical(oops)
+            log(oops)
             raise NegativeBalance()
-        logger.info("Checked the balances.")
+        log("Checked the balances.")
 
     def transfer_for_real(self, transfers):
         db = self.db
@@ -454,7 +453,7 @@ def update_stats(self):
              WHERE ts_end='1970-01-01T00:00:00+00'::timestamptz
 
         """, {'ts_start': self.ts_start})
-        logger.info("Updated payday stats.")
+        log("Updated payday stats.")
 
     def update_cached_amounts(self):
         now = aspen.utils.utcnow()
@@ -542,7 +541,7 @@ def update_cached_amounts(self):
 
             """)
         self.clean_up()
-        logger.info("Updated receiving amounts.")
+        log("Updated receiving amounts.")
 
     def end(self):
         self.ts_end = self.db.one("""
diff --git a/liberapay/elsewhere/_base.py b/liberapay/elsewhere/_base.py
--- a/liberapay/elsewhere/_base.py
+++ b/liberapay/elsewhere/_base.py
@@ -19,6 +19,7 @@
 from liberapay.exceptions import LazyResponse
 
 
+logging.basicConfig(level=logging.DEBUG)
 logger = logging.getLogger('liberapay.elsewhere')
 
 


Test patch:
diff --git a/tests/py/test_payday.py b/tests/py/test_payday.py
--- a/tests/py/test_payday.py
+++ b/tests/py/test_payday.py
@@ -144,7 +144,7 @@ def check():
         Payday.start().update_cached_amounts()
         check()
 
-    @mock.patch('liberapay.billing.payday.logger.info')
+    @mock.patch('liberapay.billing.payday.log')
     def test_start_prepare(self, log):
         self.clear_tables()
         self.make_participant('carl', balance=10)