From fb8e6cabcbd6fd216f786f9fe7752740c17ceefc Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 16 Feb 2021 04:15:09 -0500 Subject: [PATCH] fix error log location --- archivebox/config.py | 10 ++++++++++ archivebox/core/settings.py | 9 +-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/archivebox/config.py b/archivebox/config.py index 41e8c34c..2b9e942c 100644 --- a/archivebox/config.py +++ b/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(), ( diff --git a/archivebox/core/settings.py b/archivebox/core/settings.py index e0764585..e92787ea 100644 --- a/archivebox/core/settings.py +++ b/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")