summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-11-01 14:10:02 -0700
committerScott Gasch <[email protected]>2021-11-01 14:10:02 -0700
commitacacd9d2e942d084631e99e94ee430fd26ae9893 (patch)
tree56bedbc8b3237a6f10264f3b448a176bcdcb89ab
parenteb9e6df32ed696158bf34dba6464277b648f5c74 (diff)
Overrides + debugging modules / functions in logging.
-rw-r--r--arper.py34
-rw-r--r--cached/weather_data.py11
-rw-r--r--cached/weather_forecast.py3
-rw-r--r--logging_utils.py8
4 files changed, 36 insertions, 20 deletions
diff --git a/arper.py b/arper.py
index 2fc0767..4d6a3a2 100644
--- 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
diff --git a/cached/weather_data.py b/cached/weather_data.py
index d2bf787..45b6e6e 100644
--- a/cached/weather_data.py
+++ b/cached/weather_data.py
@@ -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
diff --git a/cached/weather_forecast.py b/cached/weather_forecast.py
index 2509f43..7855658 100644
--- a/cached/weather_forecast.py
+++ b/cached/weather_forecast.py
@@ -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:
diff --git a/logging_utils.py b/logging_utils.py
index eec0798..7be31e3 100644
--- a/logging_utils.py
+++ b/logging_utils.py
@@ -93,6 +93,12 @@ cfg.add_argument(
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,
default=False,
@@ -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'):