SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
spiderfoot: Add logPath() to SpiderFootHelpers (#1356)
bcoles8f201e224f0c
diff --git a/spiderfoot/helpers.py b/spiderfoot/helpers.pyindex 2d762491..6e5a3c17 100644--- a/spiderfoot/helpers.py+++ b/spiderfoot/helpers.py@@ -41,6 +41,20 @@ class SpiderFootHelpers():os.makedirs(path, exist_ok=True)return path+ @staticmethod+ def logPath() -> str:+ """Returns the file system location of SpiderFoot log files.++ Returns:+ str: SpiderFoot data file system path+ """+ path = os.environ.get('SPIDERFOOT_LOGS')+ if not path:+ path = f"{Path.home()}/.spiderfoot/logs"+ if not os.path.isdir(path):+ os.makedirs(path, exist_ok=True)+ return path+@staticmethoddef targetTypeFromString(target: str) -> None:"""Return the scan target seed data type for the specified scan target input.diff --git a/spiderfoot/logger.py b/spiderfoot/logger.pyindex e9a4da27..e9ac0c4d 100644--- a/spiderfoot/logger.py+++ b/spiderfoot/logger.py@@ -2,11 +2,8 @@ import loggingimport sysfrom contextlib import suppressfrom logging.handlers import QueueHandler, QueueListener-from pathlib import Path-from spiderfoot import SpiderFootDb--log_format = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")+from spiderfoot import SpiderFootDb, SpiderFootHelpersclass SpiderFootSqliteLogHandler(logging.Handler):@@ -74,11 +71,9 @@ def logListenerSetup(loggingQueue, opts: dict = None) -> 'logging.handlers.Queueconsole_handler = logging.StreamHandler(sys.stderr)# Log debug messages to file- log_dir = Path(__file__).parent.parent / "log"- # Create log directory if it doesn't exist- log_dir.mkdir(exist_ok=True)+ log_dir = SpiderFootHelpers.logPath()debug_handler = logging.handlers.TimedRotatingFileHandler(- str(log_dir / "spiderfoot.debug.log"),+ f"{log_dir}/spiderfoot.debug.log",when="d",interval=1,backupCount=30@@ -86,7 +81,7 @@ def logListenerSetup(loggingQueue, opts: dict = None) -> 'logging.handlers.Queue# Log error messages to fileerror_handler = logging.handlers.TimedRotatingFileHandler(- str(log_dir / "spiderfoot.error.log"),+ f"{log_dir}/spiderfoot.error.log",when="d",interval=1,backupCount=30@@ -98,6 +93,7 @@ def logListenerSetup(loggingQueue, opts: dict = None) -> 'logging.handlers.Queueerror_handler.addFilter(lambda x: x.levelno >= logging.WARN)# Set log format+ log_format = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")console_handler.setFormatter(log_format)debug_handler.setFormatter(log_format)error_handler.setFormatter(log_format)diff --git a/test/unit/test_spiderfoothelpers.py b/test/unit/test_spiderfoothelpers.pyindex 3411c173..e51dbcea 100644--- a/test/unit/test_spiderfoothelpers.py+++ b/test/unit/test_spiderfoothelpers.py@@ -25,6 +25,13 @@ class TestSpiderFootHelpers(unittest.TestCase):cache_path = SpiderFootHelpers.cachePath()self.assertIsInstance(cache_path, str)+ def test_log_path_should_return_a_string(self):+ """+ Test logPath()+ """+ log_path = SpiderFootHelpers.logPath()+ self.assertIsInstance(log_path, str)+def test_target_type(self):"""Test targetType(target)