Merge pull request #34632 from eliasp/2016.3-create-logdir-when-needed

Try to create the log directory when not present yet
This commit is contained in:
Thomas S Hatch 2016-07-22 11:34:31 -06:00 committed by GitHub
commit eba34f7f4c

View file

@ -631,6 +631,19 @@ def setup_logfile_logger(log_path, log_level='error', log_format=None,
shutdown_multiprocessing_logging_listener()
sys.exit(2)
else:
# make sure, the logging directory exists and attempt to create it if necessary
log_dir = os.path.dirname(log_path)
if not os.path.exists(log_dir):
logging.getLogger(__name__).info(
'Log directory not found, trying to create it: {0}'.format(log_dir)
)
try:
os.makedirs(log_dir, mode=0o700)
except OSError as ose:
logging.getLogger(__name__).warning(
'Failed to create directory for log file: {0} ({1})'.format(log_dir, ose)
)
return
try:
# Logfile logging is UTF-8 on purpose.
# Since salt uses YAML and YAML uses either UTF-8 or UTF-16, if a