alexsilva / supervisor

Supervisor process control system for Windows
http://supervisord.org
Other
122 stars 27 forks source link

Add a possibility to change service log path when supervisor is running as a windows service #46

Open atm84a opened 1 year ago

atm84a commented 1 year ago

Currently the location and name of Supervisor Windows service log is "hardcoded" in supervisor/services.py and is the same as location of a configuration file:

# The log goes to the location of the configuration file
if supervisor_conf is not None:
    config_dir = os.path.dirname(supervisor_conf)
else:  # or to python home
    config_dir = os.getcwd()

log_path = os.path.join(config_dir, self.slugify(self._svc_name_) + "-service.log")
hdl = logging.handlers.RotatingFileHandler(log_path,
                                           maxBytes=1024 ** 2,
                                           backupCount=3)

This way we have logs scattered in different places over filesystem w/o a possibility for bulk archiving. It would be convenient to be able to configure Windows service log in supervisord.conf file along with the regular supervisor like below (service_logfile is a proposal):

[supervisord]
logfile = c:/logs/supervisord.log
service_logfile = c:/logs/supervisor-service.log 
alexsilva commented 1 year ago

It is possible to do this but currently only the path to the configuration file is used. This would require parsing the supervisor file, and any failure in that process would prevent the logger from working.

atm84a commented 1 year ago

I can prepare a PR with that change if you have no objections.

Parsing a config file is pretty straightforward: image

Than we can initialize service logger with a log file path from the config. In case of config reading failure we can keep existing behavior after a bit of restructuring like below: image

alexsilva commented 1 year ago

It is possible to use the system registry and pass this path right when installing the service. Parsing the supervisor file can cause a lot of failures.

Config settings

Custom options

Set/Save option

An important point is to have a valid path and keep the existing file name. Validate the directory with Argparser.