Option for saving log files to recording output location?

MrCruesliPants

New Member
Hi,

I hope I landed in the right place with this more general question. The OBS log files have helped me a lot in understanding OBS better and troubleshooting any problems I've had. I really like the log files. So much in fact, that I would like to store a log file with every recording that I make, ideally with same file name as the video output, but with a .log extension.

As far as I can tell, log files are not intended to be used this way. What are my options? The best I can come up with for now, is manually copying the matching log file from the log file location to my recording output location after each recording. I dislike manual processes – I tend to mess them up – so I'm also trying to think how I could do this in a better way. How deep would I have to go to get this functionality through a (scripted) plugin?

Any and all insights would be helpful. Thank you!
 

MrCruesliPants

New Member
If anybody is also looking for a way to do this, I implemented saving the log files with recordings as a OBS Python script:


Python:
try:
    import obspython as obs
except ModuleNotFoundError:
    print("Module obspython not found, assuming execution outside OBS. Continuing...")

from pathlib import Path
import json


logs_path = Path.home() / r"AppData\Roaming\obs-studio\logs"  # might need to be configured
records_path = Path.home() / r"home\records"  # needs to be configured
records_json = records_path / "recordings.json"


def write_existing(output: Path, search_dir: Path, pattern="*"):
    output.write_text(json.dumps(tuple(str(mkv_path) for mkv_path in search_dir.rglob(pattern)), indent=2))   


def read_existing(input: Path):
    return set(Path(mkv_path) for mkv_path in json.loads(input.read_text()))


def get_most_recent_log(logs_path: Path) -> str:
    return sorted(tuple(logs_path.glob("*.txt")))[-1].read_text()


def on_event(event):

    if event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTED:
        write_existing(records_json, records_path, pattern="*.mkv")

    if event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPED:
        new_recordings = set(records_path.rglob("*.mkv")) - read_existing(records_json)
        if len(new_recordings) != 1:
            raise Exception(f"Scanned {records_path}, {len(new_recordings)} recordings found! Expected exactly 1.")
        (records_path / f"{next(iter(new_recordings)).stem}.txt").write_text(get_most_recent_log(logs_path=logs_path))
        records_json.unlink()


def script_load(settings):
    write_existing(records_json, records_path, pattern="*.mkv")
    obs.obs_frontend_add_event_callback(on_event)

Thanks to the kind people in Discord for their help!
 
Top