Overrides + debugging modules / functions in logging.
authorScott Gasch <[email protected]>
Mon, 1 Nov 2021 21:10:02 +0000 (14:10 -0700)
committerScott Gasch <[email protected]>
Mon, 1 Nov 2021 21:10:02 +0000 (14:10 -0700)
arper.py
cached/weather_data.py
cached/weather_forecast.py
logging_utils.py

index 2fc07674eedd0b8206586323ccb03bdea240fb33..4d6a3a2baa8900a4e6f5f535ad846766b2d353d7 100644 (file)
--- a/arper.py
+++ b/arper.py
@@ -78,23 +78,6 @@ class Arper(persistent.Persistent):
     def get_mac_by_ip(self, ip: str) -> Optional[str]:
         return self.state.inverse.get(ip, None)
 
-    @overrides
-    def save(self) -> bool:
-        if len(self.state) > config.config['arper_min_entries_to_be_valid']:
-            logger.debug(
-                f'Persisting state to {config.config["arper_cache_location"]}'
-            )
-            with file_utils.FileWriter(config.config['arper_cache_location']) as wf:
-                for (mac, ip) in self.state.items():
-                    mac = mac.lower()
-                    print(f'{mac}, {ip}', file=wf)
-            return True
-        else:
-            logger.warning(
-                f'Only saw {len(self.state)} entries; needed at least {config.config["arper_min_entries_to_be_valid"]} to bother persisting.'
-            )
-            return False
-
     @classmethod
     @overrides
     def load(cls) -> Any:
@@ -125,3 +108,20 @@ class Arper(persistent.Persistent):
 
         logger.debug('No usable saved state found')
         return None
+
+    @overrides
+    def save(self) -> bool:
+        if len(self.state) > config.config['arper_min_entries_to_be_valid']:
+            logger.debug(
+                f'Persisting state to {config.config["arper_cache_location"]}'
+            )
+            with file_utils.FileWriter(config.config['arper_cache_location']) as wf:
+                for (mac, ip) in self.state.items():
+                    mac = mac.lower()
+                    print(f'{mac}, {ip}', file=wf)
+            return True
+        else:
+            logger.warning(
+                f'Only saw {len(self.state)} entries; needed at least {config.config["arper_min_entries_to_be_valid"]} to bother persisting.'
+            )
+            return False
index d2bf7870c9bbcb98ba164a5f797a47eaf41081b5..45b6e6efc5d9d3c4cbd07f0996633d835aa4a98a 100644 (file)
@@ -5,9 +5,11 @@ import datetime
 import json
 import logging
 import os
-from typing import List
+from typing import Any, List
 import urllib.request
 
+from overrides import overrides
+
 import argparse_utils
 import config
 import datetime_utils
@@ -179,7 +181,8 @@ class CachedWeatherData(persistent.Persistent):
             )
 
     @classmethod
-    def load(cls):
+    @overrides
+    def load(cls) -> Any:
         if persistent.was_file_written_within_n_seconds(
                 config.config['weather_data_cachefile'],
                 config.config['weather_data_stalest_acceptable'].total_seconds(),
@@ -190,7 +193,8 @@ class CachedWeatherData(persistent.Persistent):
                 return cls(weather_data)
         return None
 
-    def save(self):
+    @overrides
+    def save(self) -> bool:
         import pickle
         with open(config.config['weather_data_cachefile'], 'wb') as wf:
             pickle.dump(
@@ -198,3 +202,4 @@ class CachedWeatherData(persistent.Persistent):
                 wf,
                 pickle.HIGHEST_PROTOCOL,
             )
+        return True
index 2509f4343b237cf331098a8a65003e1043144b95..78556586204dff83ac51926795ad9beff682d4cb 100644 (file)
@@ -9,6 +9,7 @@ import urllib.request
 import astral  # type: ignore
 from astral.sun import sun  # type: ignore
 from bs4 import BeautifulSoup  # type: ignore
+from overrides import overrides
 import pytz
 
 import argparse_utils
@@ -129,6 +130,7 @@ class CachedDetailedWeatherForecast(object):
                 )
 
     @classmethod
+    @overrides
     def load(cls):
         if persistent.was_file_written_within_n_seconds(
                 config.config['weather_forecast_cachefile'],
@@ -140,6 +142,7 @@ class CachedDetailedWeatherForecast(object):
                 return cls(weather_data)
         return None
 
+    @overrides
     def save(self):
         import pickle
         with open(config.config['weather_forecast_cachefile'], 'wb') as wf:
index eec07984b282b9a0ef1e4adea7ab6951a0abc71e..7be31e3c7c7d530215538e53922ae2070a70b342 100644 (file)
@@ -92,6 +92,12 @@ cfg.add_argument(
     default=False,
     help='Should we prepend pid/tid data to all log messages?'
 )
+cfg.add_argument(
+    '--logging_debug_modules',
+    action=argparse_utils.ActionNoYes,
+    default=False,
+    help='Should we prepend module/function data to all log messages?'
+)
 cfg.add_argument(
     '--logging_info_is_print',
     action=argparse_utils.ActionNoYes,
@@ -379,6 +385,8 @@ def initialize_logging(logger=None) -> logging.Logger:
     fmt = config.config['logging_format']
     if config.config['logging_debug_threads']:
         fmt = f'%(process)d.%(thread)d|{fmt}'
+    if config.config['logging_debug_modules']:
+        fmt = f'%(filename)s:%(funcName)s:%(lineno)s|{fmt}'
 
     if config.config['logging_syslog']:
         if sys.platform not in ('win32', 'cygwin'):