Skip to content

Commit

Permalink
Create a symlink to the latest log directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneken authored and dirk-thomas committed Sep 17, 2015
1 parent 00e80d0 commit 28f8361
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tools/rosgraph/src/rosgraph/roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@

class LoggingException: pass

def renew_latest_logdir(logfile_dir):
log_dir = os.path.dirname(logfile_dir)
latest_dir = os.path.join(log_dir, 'latest')
if os.path.lexists(latest_dir):
if not os.path.islink(latest_dir):
return False
os.remove(latest_dir)
os.symlink(logfile_dir, latest_dir)
return True

def configure_logging(logname, level=logging.INFO, filename=None, env=None):
"""
Configure Python logging package to send log files to ROS-specific log directory
Expand Down Expand Up @@ -78,6 +88,14 @@ def configure_logging(logname, level=logging.INFO, filename=None, env=None):
elif os.path.isfile(logfile_dir):
raise LoggingException("Cannot save log files: file [%s] is in the way"%logfile_dir)

if sys.platform not in ['win32']:
try:
success = renew_latest_logdir(logfile_dir)
if not success:
sys.stderr.write("INFO: cannot create a symlink to latest log directory\n")
except OSError as e:
sys.stderr.write("INFO: cannot create a symlink to latest log directory: %s\n" % e)

if 'ROS_PYTHON_LOG_CONFIG_FILE' in os.environ:
config_file = os.environ['ROS_PYTHON_LOG_CONFIG_FILE']
else:
Expand Down

3 comments on commit 28f8361

@minshallj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having the latest symlink, but I have a small nitpick with this patch. Why doesn't it put the symlink inside of logfile_dir? This is messing up things on my system because I have changed the ROS_LOG_DIR to be /var/log/ros, and so it's now trying to make /var/log/latest which it doesn't have permissions for. Would things break if the latest symlink was moved into logfile_dir

@dirk-thomas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out. While it does work for log files created in e.g. subfolders it shouldn't try to symlink the log dir itself. Please see #795 for a patch.

Can you please clarify what messing up things on my system means? From reading the code it should gracefully fall back and not create the symlink when the location is not writable.

@minshallj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, messing things up on my system just means echoing out an error when most ros commands are run leading to me scratching my head for a while.

Please sign in to comment.