4040import importlib .util
4141import logging
4242import multiprocessing
43+ import os .path
4344import signal
4445import sys
4546import time
@@ -197,6 +198,7 @@ class DeviceServerOptions:
197198
198199 config_fpath : str
199200 logging_level : int
201+ logging_dir : str
200202
201203
202204def _check_autoproxy_feature () -> None :
@@ -308,6 +310,7 @@ def run(self):
308310 # based on a unique identifier for the device. Some devices
309311 # don't have UIDs available until after initialization, so
310312 # log to stderr until then.
313+
311314 stderr_handler = StreamHandler (sys .stderr )
312315 stderr_handler .setFormatter (_create_log_formatter (cls_name ))
313316 root_logger .addHandler (stderr_handler )
@@ -351,7 +354,10 @@ def run(self):
351354 pyro_daemon = Pyro4 .Daemon (port = port , host = host )
352355
353356 log_handler = RotatingFileHandler (
354- "%s_%s_%s.log" % (cls_name , host , port )
357+ os .path .join (
358+ self ._options .logging_dir ,
359+ "%s_%s_%s.log" % (cls_name , host , port ),
360+ )
355361 )
356362 log_handler .setFormatter (_create_log_formatter (cls_name ))
357363 root_logger .addHandler (log_handler )
@@ -560,6 +566,14 @@ def _parse_cmd_line_args(args: typing.Sequence[str]) -> DeviceServerOptions:
560566 choices = ["debug" , "info" , "warning" , "error" , "critical" ],
561567 help = "Set logging level" ,
562568 )
569+ parser .add_argument (
570+ "--logging-dir" ,
571+ action = "store" ,
572+ type = str ,
573+ default = "" ,
574+ help = "Directory where log files are written to" ,
575+ )
576+
563577 parser .add_argument (
564578 "config_fpath" ,
565579 action = "store" ,
@@ -571,6 +585,7 @@ def _parse_cmd_line_args(args: typing.Sequence[str]) -> DeviceServerOptions:
571585 return DeviceServerOptions (
572586 config_fpath = parsed .config_fpath ,
573587 logging_level = getattr (logging , parsed .logging_level .upper ()),
588+ logging_dir = parsed .logging_dir ,
574589 )
575590
576591
0 commit comments