How to use the rospkg.get_log_dir function in rospkg

To help you get started, we’ve selected a few rospkg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ros / ros_comm / tools / roslaunch / src / roslaunch / roslaunch_logs.py View on Github external
def logs_main():
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog", prog=NAME)
    options, args = parser.parse_args()
    if args:
        parser.error("%s takes no arguments"%NAME)
        
    log_dir = rospkg.get_log_dir()
    if not log_dir:
        print("Cannot determine ROS log directory", file=sys.stderr)
        sys.exit(1)
        
    run_id = get_run_id()
    if not run_id:
        # go ahead and print the log directory
        print("No active roscore", file=sys.stderr)
        print(log_dir)
        sys.exit(2)

    print(os.path.join(log_dir, run_id))
github ros / ros / tools / rosclean / src / rosclean / __init__.py View on Github external
def _get_check_dirs():
    home_dir = rospkg.get_ros_home()
    log_dir = rospkg.get_log_dir()
    dirs = [(log_dir, 'ROS node logs'),
            (os.path.join(home_dir, 'rosmake'), 'rosmake logs')]
    return [x for x in dirs if os.path.isdir(x[0])]
github ros / ros_comm / tools / rosgraph / src / rosgraph / roslogging.py View on Github external
def configure_logging(logname, level=logging.INFO, filename=None, env=None):
    """
    Configure Python logging package to send log files to ROS-specific log directory
    :param logname str: name of logger, ``str``
    :param filename: filename to log to. If not set, a log filename
        will be generated using logname, ``str``
    :param env: override os.environ dictionary, ``dict``
    :returns: log file name, ``str``
    :raises: :exc:`LoggingException` If logging cannot be configured as specified
    """
    if env is None:
        env = os.environ

    logname = logname or 'unknown'
    log_dir = rospkg.get_log_dir(env=env)
    
    # if filename is not explicitly provided, generate one using logname
    if not filename:
        log_filename = os.path.join(log_dir, '%s-%s.log'%(logname, os.getpid()))
    else:
        log_filename = os.path.join(log_dir, filename)

    logfile_dir = os.path.dirname(log_filename)
    if not os.path.exists(logfile_dir):
        try:
            makedirs_with_parent_perms(logfile_dir)
        except OSError:
            # cannot print to screen because command-line tools with output use this
            if os.path.exists(logfile_dir):
                # We successfully created the logging folder, but could not change
                # permissions of the new folder to the same as the parent folder
github hansonrobotics / HEAD / src / webui / app / monitor.py View on Github external
def get_logs(loglevel):
    """
    Collect the logs from the ros log files.
    If there is no roscore process running, then it displays the logs
    from the last run.
    """
    from roslaunch.roslaunch_logs import get_run_id
    import rospkg
    import glob
    import re

    logger.info('get logs: log level {}'.format(loglevel))
    log_cursors = request.form.copy()
    logger.debug('cursors: {}'.format(log_cursors))

    log_root = rospkg.get_log_dir()
    run_id = get_run_id()
    roscore_running = True
    if not run_id:
        roscore_running = False
        subdirs = [os.path.join(log_root, d) for d in os.listdir(log_root)
                    if os.path.isdir(os.path.join(log_root, d))]
        if subdirs:
            run_id = max(subdirs, key=os.path.getmtime)
        else:
            run_id = ''

    # some extra log files that not created by roslaunch
    extra_log_files = [os.path.join(log_root, name) for name in [
        'ros_motors_webui.log', 'sophia_Eva_Behavior.log', 'blender_api.log']]
    extra_log_files = [f for f in extra_log_files if os.path.isfile(f)]
github fkie / multimaster_fkie / fkie_node_manager_daemon / src / fkie_node_manager_daemon / screen.py View on Github external
def rosclean():
    '''
    Removes the content of the ROS-log directory. We didn't use rosclean purge because it
    removes the log-directory. This needs restart of ROS nodes or recreate log directory
    to get log again.
    '''
    d = rospkg.get_log_dir()
    if d and d != os.path.sep:
        ps = SupervisedPopen(['rm -fr %s/*' % d], stdout=subprocess.PIPE, shell=True, object_id='rosclean')
        output_err = ps.stderr.read()
        if output_err:
            raise Exception(output_err)
github ros / ros_comm / tools / roslaunch / src / roslaunch / rlutil.py View on Github external
def check_log_disk_usage():
    """
    Check size of log directory. If high, print warning to user
    """
    try:
        d = rospkg.get_log_dir()
        roslaunch.core.printlog("Checking log directory for disk usage. This may take a while.\nPress Ctrl-C to interrupt") 
        disk_usage = rosclean.get_disk_usage(d)
        # warn if over a gig
        if disk_usage > 1073741824:
            roslaunch.core.printerrlog("WARNING: disk usage in log directory [%s] is over 1GB.\nIt's recommended that you use the 'rosclean' command."%d)
        else:
            roslaunch.core.printlog("Done checking log file disk usage. Usage is <1GB.")            
    except:
        pass