Преглед на файлове

Merge pull request #1939 from pbiering/startup-log-cosmetics

Startup log cosmetics
Peter Bieringer преди 2 месеца
родител
ревизия
e64039e692
променени са 3 файла, в които са добавени 41 реда и са изтрити 3 реда
  1. 3 2
      radicale/app/__init__.py
  2. 1 1
      radicale/auth/__init__.py
  3. 37 0
      radicale/utils.py

+ 3 - 2
radicale/app/__init__.py

@@ -98,12 +98,13 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
         self._mask_passwords = configuration.get("logging", "mask_passwords")
         self._max_content_length = configuration.get("server", "max_content_length")
         self._max_resource_size = configuration.get("server", "max_resource_size")
+        logger.info("max_content_length set to: %d bytes (%sbytes)", self._max_content_length, utils.format_unit(self._max_content_length, binary=True))
         if (self._max_resource_size > (self._max_content_length * 0.8)):
             max_resource_size_limited = int(self._max_content_length * 0.8)
-            logger.warning("max_resource_size capped to: %d bytes (from %d to 80%% of max_content_length %d)", max_resource_size_limited, self._max_resource_size, self._max_content_length)
+            logger.warning("max_resource_size set to: %d bytes (%sbytes) (capped from %d to 80%% of max_content_length)", max_resource_size_limited, utils.format_unit(max_resource_size_limited, binary=True), self._max_resource_size)
             self._max_resource_size = max_resource_size_limited
         else:
-            logger.info("max_resource_size set to: %d bytes", self._max_resource_size)
+            logger.info("max_resource_size  set to: %d bytes (%sbytes)", self._max_resource_size, utils.format_unit(self._max_resource_size, binary=True))
         self._bad_put_request_content = configuration.get("logging", "bad_put_request_content")
         logger.info("log bad put request content: %s", self._bad_put_request_content)
         self._request_header_on_debug = configuration.get("logging", "request_header_on_debug")

+ 1 - 1
radicale/auth/__init__.py

@@ -142,7 +142,7 @@ class BaseAuth:
         if self._lc_username is True and self._uc_username is True:
             raise RuntimeError("auth.lc_username and auth.uc_username cannot be enabled together")
         self._auth_delay = configuration.get("auth", "delay")
-        logger.info("auth.delay: %f", self._auth_delay)
+        logger.info("auth.delay: %f seconds", self._auth_delay)
         self._failed_auth_delay = 0
         self._lock = threading.Lock()
         # cache_successful_logins

+ 37 - 0
radicale/utils.py

@@ -53,6 +53,15 @@ DATETIME_MAX_UNIXTIME: int = (datetime.MAXYEAR - 1970) * 365 * 24 * 60 * 60
 DATETIME_MIN_UNIXTIME: int = (datetime.MINYEAR - 1970) * 365 * 24 * 60 * 60
 
 
+# Number units
+UNIT_g: int = (1000 * 1000 * 1000)
+UNIT_m: int = (1000 * 1000)
+UNIT_k: int = (1000)
+UNIT_G: int = (1024 * 1024 * 1024)
+UNIT_M: int = (1024 * 1024)
+UNIT_K: int = (1024)
+
+
 def load_plugin(internal_types: Sequence[str], module_name: str,
                 class_name: str, base_class: Type[_T_co],
                 configuration: "config.Configuration") -> _T_co:
@@ -294,6 +303,34 @@ def format_ut(unixtime: int) -> str:
     return r
 
 
+def format_unit(value: float, binary: bool = False) -> str:
+    if binary:
+        if value > UNIT_G:
+            value = value / UNIT_G
+            unit = "G"
+        elif value > UNIT_M:
+            value = value / UNIT_M
+            unit = "M"
+        elif value > UNIT_K:
+            value = value / UNIT_K
+            unit = "K"
+        else:
+            unit = ""
+    else:
+        if value > UNIT_g:
+            value = value / UNIT_g
+            unit = "g"
+        elif value > UNIT_m:
+            value = value / UNIT_m
+            unit = "m"
+        elif value > UNIT_k:
+            value = value / UNIT_k
+            unit = "k"
+        else:
+            unit = ""
+    return ("%.1f %s" % (value, unit))
+
+
 def limit_str(content: str, limit: int) -> str:
     length = len(content)
     if limit > 0 and length >= limit: