def link_logfiles(self,
                      options=defaults.DEFAULT_CRAWL_OPTIONS):

        host_log_dir = self._get_logfiles_links_dest(
            options['logcrawler']['host_log_basedir'],
            options['environment'],
        )

        logs_list = self._get_logfiles_list(host_log_dir, options)

        logger.debug('Linking log files for container %s' % self.short_id)

        # create an empty dir for the container logs

        if not os.path.exists(host_log_dir):
            os.makedirs(host_log_dir)

        # Create a symlink from src to dst

        for log in logs_list:
            try:
                if not os.path.exists(log['source']):
                    logger.debug(
                        'Log file %s does not exist, but linking it anyway'
                        % log['source'])
                dest_dir = os.path.dirname(log['dest'])
                if not os.path.exists(dest_dir):
                    os.makedirs(dest_dir)
                os.symlink(log['source'], log['dest'])
                logger.info(
                    'Linking container %s %s logfile %s -> %s' %
                    (self.short_id, log['name'], log['source'], log['dest']))
            except (OSError, IOError) as e:
                logger.debug('Link already exists: %s -> %s'
                             % (log['source'], log['dest']))
            except Exception as e:
                logger.warning(e)

        # Keep record of what is linked in a file.

        try:
            log_types_file = options['logcrawler']['log_types_file']
            types_host_log_path = os.path.join(host_log_dir,
                                               log_types_file)
            with open(types_host_log_path, 'w') as outfile:
                logs_dict = [{'name': log['name'], 'type': log['type']}
                             for log in logs_list]
                json.dump(logs_dict, outfile)
        except (OSError, IOError) as e:
            # Not a critical error: move on
            logger.exception(e)
dataset/ETHPy150Open cloudviz/agentless-system-crawler/crawler/dockercontainer.py/DockerContainer.link_logfiles/original