Bladeren bron

fix error log location

Nick Sweeting 4 jaren geleden
bovenliggende
commit
fb8e6cabcb
2 gewijzigde bestanden met toevoegingen van 11 en 8 verwijderingen
  1. 10 0
      archivebox/config.py
  2. 1 8
      archivebox/core/settings.py

+ 10 - 0
archivebox/config.py

@@ -33,6 +33,7 @@ import django
 
 from hashlib import md5
 from pathlib import Path
+from datetime import datetime
 from typing import Optional, Type, Tuple, Dict, Union, List
 from subprocess import run, PIPE, DEVNULL
 from configparser import ConfigParser
@@ -1063,6 +1064,7 @@ def setup_django(out_dir: Path=None, check_db=False, config: ConfigDict=CONFIG,
 
     try:
         import django
+
         sys.path.append(str(config['PACKAGE_DIR']))
         os.environ.setdefault('OUTPUT_DIR', str(output_dir))
         assert (config['PACKAGE_DIR'] / 'core' / 'settings.py').exists(), 'settings.py was not found at archivebox/core/settings.py'
@@ -1082,6 +1084,14 @@ def setup_django(out_dir: Path=None, check_db=False, config: ConfigDict=CONFIG,
             with connection.cursor() as cursor:
                 cursor.execute("PRAGMA journal_mode=wal;")
 
+        from django.conf import settings
+
+        # log startup message to the error log
+        with open(settings.ERROR_LOG, "a+") as f:
+            command = ' '.join(sys.argv)
+            ts = datetime.now().strftime('%Y-%m-%d__%H:%M:%S')
+            f.write(f"\n> {command}; ts={ts} version={VERSION} docker={IN_DOCKER} is_tty={IS_TTY}\n")
+
         if check_db:
             sql_index_path = Path(output_dir) / SQL_INDEX_FILENAME
             assert sql_index_path.exists(), (

+ 1 - 8
archivebox/core/settings.py

@@ -210,7 +210,7 @@ class NoisyRequestsFilter(logging.Filter):
 
         return 1
 
-ERROR_LOG = LOGS_DIR / 'errors.log'
+ERROR_LOG = (LOGS_DIR / 'errors.log') if LOGS_DIR.exists() else '/dev/null'
 
 LOGGING = {
     'version': 1,
@@ -245,10 +245,3 @@ LOGGING = {
         }
     },
 }
-
-
-# log startup message to the error log
-with open(ERROR_LOG, "a+") as f:
-    command = ' '.join(sys.argv)
-    ts = datetime.now().strftime('%Y-%m-%d__%H:%M:%S')
-    f.write(f"\n> {command}; ts={ts} version={VERSION} docker={IN_DOCKER} is_tty={IS_TTY}\n")