mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
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:
commit
eba34f7f4c
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue