code: def setup_logdir(self):
      # todo: locking on logdir creation
  
      
      run_name = ncluster_globals.get_run_for_task(self)
      self.log("Creating logdir for run "+run_name)
      logdir_root = ncluster_globals.LOGDIR_ROOT
      assert logdir_root
  
      self.run(f'mkdir -p {logdir_root}')
      find_command = f'find {logdir_root} -maxdepth 1 -type d'
  
      stdout, stderr = self.run_with_output(find_command)
      logdir = f"{logdir_root}/{run_name}"
  
      counter = 0
      while logdir in stdout:
        counter += 1
        new_logdir = f'{logdir_root}/{run_name}.{counter:02d}'
        self.log(f'Warning, logdir {logdir} exists, deduping to {new_logdir}')
        logdir = new_logdir
      self.run(f'mkdir -p {logdir}')
  
      ncluster_globals.set_logdir(run_name, logdir)
      return logdir
docs: Create logdir for task/job/run. No-op if the task is not chief (0'th task of 0'th job of run)