commit d214b08f62ca04e2bd66ecee89fe7faab3ef4aae
Author: Simone Basso <bassosim...@gmail.com>
Date:   Wed Feb 22 15:22:26 2017 +0100

    log.py: make rotated logfiles sortable (#734)
    
    * log.py: make rotated logfiles sortable
---
 ooni/utils/log.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/ooni/utils/log.py b/ooni/utils/log.py
index 251e160e..6b28bedb 100644
--- a/ooni/utils/log.py
+++ b/ooni/utils/log.py
@@ -16,6 +16,18 @@ from ooni import otime
 # IPv6 destination warnings":
 logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
 
+
+class MyDailyLogFile(DailyLogFile):
+    """ Override default behavior of Twisted class such that the
+        suffix always uses two digits for months and days such that
+        the rotated log files are lexicographically sortable """
+
+    def suffix(self, tupledate):
+        if len(tupledate) < 3:  # just in case
+            return DailyLogFile.suffix(self, tupledate)
+        return "{:04d}_{:02d}_{:02d}".format(*tupledate[:3])
+
+
 def log_encode(logmsg):
     """
     I encode logmsg (a str or unicode) as printable ASCII. Each case
@@ -176,7 +188,7 @@ class OONILogger(object):
             stdout_log_level = levels['DEBUG']
 
         if config.basic.rotate == 'daily':
-            logfile = DailyLogFile(log_filename, log_folder)
+            logfile = MyDailyLogFile(log_filename, log_folder)
         elif config.basic.rotate == 'length':
             logfile = LogFile(log_filename, log_folder,
                               rotateLength=int(human_size_to_bytes(



_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to