diff --git a/example-conf.yml b/example-conf.yml index 1f27c7c..fa99155 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -86,6 +86,14 @@ pylink: # This defaults to False if not set. #join_empty_channels: false + # Determines where the plugins write their databases. The path can be relative to the directory + # PyLink is run from. Defaults to the current directory. + #data_dir: "" + + # Determines where the PID file is written. The path can be relative to the directory PyLink is + # run from. Defaults to the current directory. + #pid_dir: "" + login: # NOTE: for users migrating from PyLink < 1.1, the old login:user/login:password settings # have been deprecated. We strongly recommend migrating to the new "accounts:" block below, as @@ -649,10 +657,14 @@ logging: "#services": loglevel: INFO + # The directory where the log files are written. The path can be relative to the directory + # PyLink is run from. Defaults to "log/". + #log_dir: "log" + files: - # Logs to file targets. These will be placed in the log/ folder in the - # PyLink directory, with a filename based on the current instance name - # and the target name: instancename-targetname.log + # Logs to file targets. These will be placed in the folder specified by log_dir with a + # filename based on the current instance name and the target name: + # instancename-targetname.log # When running with "pylink", this will create log/pylink-errors.log # When running with "pylink someconf.yml", this will create log/someconf-errors.log diff --git a/launcher.py b/launcher.py index 3b974c8..551d37e 100644 --- a/launcher.py +++ b/launcher.py @@ -25,7 +25,8 @@ def _main(): # Write and check for an existing PID file unless specifically told not to. if not args.no_pid: - pidfile = '%s.pid' % conf.confname + pid_dir = conf.conf['pylink'].get('pid_dir', '') + pidfile = os.path.join(pid_dir, '%s.pid' % conf.confname) pid_exists = False pid = None if os.path.exists(pidfile): diff --git a/log.py b/log.py index cc49d31..498b3f0 100644 --- a/log.py +++ b/log.py @@ -15,9 +15,6 @@ from . import conf, world # Stores a list of active file loggers. fileloggers = [] -logdir = os.path.join(os.getcwd(), 'log') -os.makedirs(logdir, exist_ok=True) - # TODO: perhaps make this format configurable? _format = '%(asctime)s [%(levelname)s] %(message)s' logformatter = logging.Formatter(_format) @@ -47,11 +44,19 @@ def _make_file_logger(filename, level=None): """ Initializes a file logging target with the given filename and level. """ + logconf = conf.conf.get('logging', {}) + + logdir = logconf.get('log_dir') + if logdir is None: + logdir = os.path.join(os.getcwd(), 'log') + + os.makedirs(logdir, exist_ok=True) + # Use log names specific to the current instance, to prevent multiple # PyLink instances from overwriting each others' log files. target = os.path.join(logdir, '%s-%s.log' % (conf.confname, filename)) - logrotconf = conf.conf.get('logging', {}).get('filerotation', {}) + logrotconf = logconf.get('filerotation', {}) # Max amount of bytes per file, before rotation is done. Defaults to 20 MiB. maxbytes = logrotconf.get('max_bytes', 20971520) diff --git a/structures.py b/structures.py index e81560f..576c936 100644 --- a/structures.py +++ b/structures.py @@ -201,7 +201,12 @@ class DataStore: Generic database class. Plugins should use a subclass of this such as JSONDataStore or PickleDataStore. """ - def __init__(self, name, filename, save_frequency=None, default_db=None): + def __init__(self, name, filename, save_frequency=None, default_db=None, data_dir=None): + if data_dir is None: + data_dir = conf.conf['pylink'].get('data_dir', '') + + filename = os.path.join(data_dir, filename) + self.name = name self.filename = filename self.tmp_filename = filename + '.tmp'