added file logging and automatically load config/cookies.txt if non is given via ytdlp.json file.
This commit is contained in:
parent
ccd5b0607e
commit
e0058d969f
2 changed files with 21 additions and 0 deletions
|
|
@ -99,6 +99,7 @@ Certain values can be set via environment variables, using the `-e` parameter on
|
||||||
* __YTP_BASIC_MODE__: Whether to run WebUI in basic mode. Defaults to `false`. In basic mode, A minimal UI will be shown, the majority of the features will be disabled.
|
* __YTP_BASIC_MODE__: Whether to run WebUI in basic mode. Defaults to `false`. In basic mode, A minimal UI will be shown, the majority of the features will be disabled.
|
||||||
* __YTP_DEFAULT_PRESET__: The default preset to use for the download. Defaults to `default`.
|
* __YTP_DEFAULT_PRESET__: The default preset to use for the download. Defaults to `default`.
|
||||||
* __YTP_INSTANCE_TITLE__: The title of the instance. Defaults to empty string.
|
* __YTP_INSTANCE_TITLE__: The title of the instance. Defaults to empty string.
|
||||||
|
* __YTP_FILE_LOGGING__: Whether to log to file. Defaults to `false`.
|
||||||
|
|
||||||
## Running behind a reverse proxy
|
## Running behind a reverse proxy
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
from logging.handlers import RotatingFileHandler
|
||||||
from multiprocessing.managers import SyncManager
|
from multiprocessing.managers import SyncManager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
@ -139,6 +140,9 @@ class Config:
|
||||||
instance_title: str | None = None
|
instance_title: str | None = None
|
||||||
"The title of the instance."
|
"The title of the instance."
|
||||||
|
|
||||||
|
file_logging: bool = False
|
||||||
|
"Enable file logging."
|
||||||
|
|
||||||
_manual_vars: tuple = (
|
_manual_vars: tuple = (
|
||||||
"temp_path",
|
"temp_path",
|
||||||
"config_path",
|
"config_path",
|
||||||
|
|
@ -179,6 +183,7 @@ class Config:
|
||||||
"ui_update_title",
|
"ui_update_title",
|
||||||
"pip_ignore_updates",
|
"pip_ignore_updates",
|
||||||
"basic_mode",
|
"basic_mode",
|
||||||
|
"file_logging",
|
||||||
)
|
)
|
||||||
"The variables that are booleans."
|
"The variables that are booleans."
|
||||||
|
|
||||||
|
|
@ -359,6 +364,12 @@ class Config:
|
||||||
LOG.info("keep archive option is enabled.")
|
LOG.info("keep archive option is enabled.")
|
||||||
self.ytdl_options["download_archive"] = os.path.join(self.config_path, "archive.log")
|
self.ytdl_options["download_archive"] = os.path.join(self.config_path, "archive.log")
|
||||||
|
|
||||||
|
cookiesFile: str = os.path.join(self.config_path, "cookies.txt")
|
||||||
|
|
||||||
|
if os.path.exists(cookiesFile) and self.ytdl_options.get("cookiefile", None) is None:
|
||||||
|
LOG.info(f"Using cookies from '{cookiesFile}' as default.")
|
||||||
|
self.ytdl_options["cookiefile"] = cookiesFile
|
||||||
|
|
||||||
if self.temp_keep:
|
if self.temp_keep:
|
||||||
LOG.info("Keep temp files option is enabled.")
|
LOG.info("Keep temp files option is enabled.")
|
||||||
|
|
||||||
|
|
@ -368,6 +379,15 @@ class Config:
|
||||||
if self.basic_mode:
|
if self.basic_mode:
|
||||||
LOG.info("The frontend is running in basic mode.")
|
LOG.info("The frontend is running in basic mode.")
|
||||||
|
|
||||||
|
if self.file_logging:
|
||||||
|
handler = RotatingFileHandler(
|
||||||
|
os.path.join(self.config_path, "app.log"), maxBytes=1 * 1024 * 1024, backupCount=3
|
||||||
|
)
|
||||||
|
handler.setLevel(logging.ERROR)
|
||||||
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
logging.getLogger().addHandler(handler)
|
||||||
|
|
||||||
self.started = time.time()
|
self.started = time.time()
|
||||||
|
|
||||||
def _get_attributes(self) -> dict:
|
def _get_attributes(self) -> dict:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue