mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-23 11:12:47 +01:00
Implement path configuration for files created by pylink (#659)
* Configure log directory Signed-off-by: Celelibi <celelibi@gmail.com> * Configure data store directory Signed-off-by: Celelibi <celelibi@gmail.com> * Configure PID file directory Signed-off-by: Celelibi <celelibi@gmail.com>
This commit is contained in:
parent
947732580a
commit
9470e9329a
@ -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
|
||||
|
@ -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):
|
||||
|
13
log.py
13
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)
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user