enh(logging): add a log_to_file setting so motion can log to stdout - #3394
Open
JamBalaya56562 wants to merge 1 commit into
Open
enh(logging): add a log_to_file setting so motion can log to stdout#3394JamBalaya56562 wants to merge 1 commit into
JamBalaya56562 wants to merge 1 commit into
Conversation
motion's output was unconditionally redirected to <log_path>/motion.log, so containerized setups could not see it via 'docker logs' (motioneye-project#3330). Add a log_to_file setting to settings.py and motioneye.conf.sample, and have motionctl honour it: when disabled, motion inherits motionEye's own stdout/stderr instead of being redirected to a file. The existing -l CLI flag is now resolved in load_settings() alongside -d, which makes settings.LOG_TO_FILE the single source of truth and lets the configure_logging() callers drop the flag argument. Daemon mode still forces file logging, since daemonizing sends stdout/stderr to /dev/null. Default is false, matching the -l default: systemd and Docker already run motionEye without -l/-b and get its log on stderr, so this only makes motion consistent with it. The sysv init script passes -l -b explicitly and is unaffected. Also drop two leftover debug writes in configure_logging() that printed to stderr on every invocation, and guard the log handler against a missing log file now that its absence is the default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
log_to_filesetting tosettings.pyandmotioneye.conf.sample, overridable by the existing-lCLI flagmotionctlhonour it: when file logging is off, motion inherits motionEye's own stdout/stderr instead of being redirected to<log_path>/motion.logFixes #3330. Implements @MichaIng's outline from #3330 (comment).
Why
motion's output was redirected to
<log_path>/motion.logunconditionally, so containerized setups could not see it throughdocker logsat all. motionEye's own log already goes to stderr by default — only motion's was diverted to a file.How
settings.py/motioneye.conf.sample— newlog_to_filesetting. Thelog_pathnote is on thelog_to_fileentry, since that is where a reader lands.meyectl.py—-lis now resolved inload_settings()next to-d, i.e. after the config file is parsed, so the CLI wins. That makessettings.LOG_TO_FILEthe single source of truth, and the fiveconfigure_logging()call sites no longer need to pass the flag (shell.pyneeds no new import).server.py—-bstill forces file logging, because daemonizing redirects stdout/stderr to/dev/null(Daemon.daemonize()); without this, motion's output would be lost.motionctl.py—_get_motion_log_file()returnsNonewhen file logging is off, which makesPopenhand motionEye's own stdout/stderr to motion.handlers/log.py—/log/motion/now returns 404 instead of an unhandledFileNotFoundError, since a missingmotion.logis the default state after this change.Default is
false— rationaleextra/motioneye.systemdstartserver -c …-l/-b→ motionEye logs to stderr, only motion goes to a filedocker/entrypoint.shstartserver -c …extra/motioneye.sysvstartserver -c … -l -bSo
falseleaves motionEye's own logging untouched and merely makes motion consistent with it, while sysv users are unaffected. Atruedefault would instead push every systemd user's motionEye log out of journald and into a file, which is the more disruptive change.Behaviour changes to be aware of
motion.logis no longer written by default. systemd/Docker users get motion's output in journald /docker logs; setlog_to_file trueto restore the file.-lcan only enable file logging, not disable it (log_to_file truein the config cannot be overridden back tofalseon the command line). This mirrors how-drelates tolog_level, so I kept it consistent — happy to add a--no-log-to-fileif you'd prefer it to be symmetric.sys.stderr.writedebug lines inconfigure_logging()that printed on every single invocation. They're squarely in the way of this PR's goal (clean stdout), but say the word and I'll split them out.Deliberately out of scope
motionctl.start()(log_fileis never closed).server.pyexiting fatally whenLOG_PATHisn't writable — arguably more wrong now that the directory can go unused, but pre-existing.Validation
pytest tests/→ 141 passed (139 before + the new ones);ruff check,ruff format --check,flake8,isort,codespellall clean with the repo's pre-commit args.tests/test_meyectl.py(config parseslog_to_fileas a bool,-loverrides it),tests/test_motionctl.py(_get_motion_log_file()returnsNonevs. an openmotion.log),tests/test_handlers/test_log.py(404 when absent, still served when present).log_to_fileunset)[0:motion] [NTC] …lines appear on motionEye's stdout; nomotion.logcreated ✅log_to_file truemotion.log+motioneye.logwritten, stdout quiet ✅-lwithlog_to_file false-bwithlog_to_file falsemotion.logstill written — output not lost to/dev/null✅GET /log/motion/withlog_to_file false