Fix comments and spacing
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 19 Dec 2019 16:16:35 +0000 (17:16 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 10 Nov 2021 09:28:29 +0000 (10:28 +0100)
src/log_helpers.py

index 288a695..b76a011 100644 (file)
@@ -160,7 +160,8 @@ def get_logger(name, *args, **kwargs):
 
 
 class I2nLogger:
-    """ a more convenient logger
+    """
+    A more convenient logger
 
     Features::
     * can be used without ".format()" as follows::
@@ -195,8 +196,8 @@ class I2nLogger:
     def __init__(self, name, level=INFO, fmt=DEFAULT_SHORT_LEVEL_FORMAT,
                  datefmt=DEFAULT_SHORT_LEVEL_DATE_FORMAT,
                  streams=STDOUT, files=None, handlers=None):
-        """ creates a I2nLogger; forwards args to logging.getLogger
-
+        """
+        Creates a I2nLogger; forwards args to logging.getLogger
 
         :param str name: name of this logger, best practice is module name
         :param int level: best use one of the constants DEBUG, INFO NOTICE,
@@ -324,7 +325,7 @@ class I2nLogger:
             self._log.log(level, message_formatted, **kwargs)
 
     def _log_no_test(self, level, message, *args, **kwargs):
-        """ same as log() but without the isinstance test for internal use"""
+        """Same as log() but without the isinstance test for internal use."""
         if level >= self._level:
             try:
                 message_formatted = message.format(*args)
@@ -333,9 +334,10 @@ class I2nLogger:
             self._log.log(level, message_formatted, **kwargs)
 
     def log_count_if_interesting(self, count, level=INFO, counter_name=None):
-        """ Log value of a counter in gradually coarser intervals
+        """
+        Log value of a counter in gradually coarser intervals
 
-        see :py:func:`is_interesting_count` for definition of "interesting"
+        See :py:func:`is_interesting_count` for definition of "interesting".
         """
         if is_interesting_count(count):
             if counter_name:
@@ -344,15 +346,16 @@ class I2nLogger:
                 self.log(level, 'Counter is at {0}', count)
 
     def get_level(self):
-        """ return int level of this logger """
+        """Return int level of this logger."""
         return self._level
 
     def get_level_str(self):
-        """ returns :py:func:`logging.getLevelName` on :py:meth:`get_level` """
+        """Returns :py:func:`logging.getLevelName` on :py:meth:`get_level`."""
         return logging.getLevelName(self._level)
 
     def set_level(self, new_level):
-        """ set level given an int or a str
+        """
+        Set level given an int or a str.
 
         :arg new_level: int or str (str is converted to lower case)
         :raises: KeyError if new_level is a string that is not in
@@ -411,7 +414,8 @@ class I2nLogger:
 
 
 def n_digits(number):
-    """ returns the number of digits a number has in decimal format
+    """
+    Returns the number of digits a number has in decimal format
 
     :returns: 1 for 1...9, 2 for 10...99, 3 for 100...999, ...
               0 for 0 (and everything else beween -1 and 1)
@@ -422,8 +426,10 @@ def n_digits(number):
     else:
         return floor(log10(abs(number)))+1
 
+
 def is_interesting_count(counter):
-    """ return True if counter has reached an "interesting" value
+    """
+    Return True if counter has reached an "interesting" value
 
     For the counter to be "interesting" becomes ever harder. At first it is
     easy (returns True for 1,2,3,6,10), then becomes harder (True only for
@@ -439,9 +445,8 @@ def is_interesting_count(counter):
                 log('reached iteration {0}'.format(counter))
             counter += 1
 
-    Or implicitly using I2nLogger::log_count_if_interesting(counter)
+    Used by :py:meth:`I2nLogger::log_count_if_interesting`.
 
     :returns: True for a few values of counter, False most of the time
     """
-
     return float(counter) / 10.**(n_digits(counter)-1.) in (1., 2., 3., 6.)