Method: Roby::Application#find_and_create_log_dir

Defined in:
lib/roby/app.rb

#find_and_create_log_dir(time_tag = self.time_tag) ⇒ String

Create a log directory for the given time tag, and make it this app’s log directory

The time tag given to this method also becomes the app’s time tag

Parameters:

  • time_tag (String) (defaults to: self.time_tag)

Returns:

  • (String)

    the path to the log directory



1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
# File 'lib/roby/app.rb', line 1553

def find_and_create_log_dir(time_tag = self.time_tag)
    base_dir  = log_base_dir
    @time_tag = time_tag

    loop do
        log_dir  = Roby::Application.unique_dirname(base_dir, "", time_tag)
        new_dirs = []

        dir = log_dir
        until File.directory?(dir)
            new_dirs << dir
            dir = File.dirname(dir)
        end

        # Create all paths necessary, but check for possible concurrency
        # issues with other Roby-based tools creating a log dir with the
        # same name
        failed = new_dirs.reverse.any? do |path_element|
            begin
                FileUtils.mkdir(path_element)
                false
            rescue Errno::EEXIST
                true
            end
        end

        unless failed
            new_dirs.delete(log_dir)
            created_log_dirs << log_dir
            created_log_base_dirs.concat(new_dirs)
            @log_dir = log_dir
            
            return log_dir
        end
    end
end