Directory where rotated agent logs are stored.

The method also creates a log directory if required.

@since 1.613
167498
protected @Nonnull File getLogDir() {
        File dir = new File(Jenkins.getInstance().getRootDir(),"logs/slaves/"+nodeName);
        if (!dir.exists() && !dir.mkdirs()) {
            LOGGER.severe("Failed to create agent log directory " + dir.getAbsolutePath());
        }
        return dir;
    }
620143
public static void createDirectory(File location) throws IOException {
    if (!(location.exists() || location.mkdirs() || location.isDirectory())) {
      throw new IOException("Could not create directory at " + location);
    }
  }
570333
protected void logSystemPropertiesAndBasedir() {
        if (getLog().isDebugEnabled()) {

            final StringBuilder builder = new StringBuilder();

            builder.append("\n+=================== [System properties]\n");
            builder.append("|\n");

            // Sort the system properties
            final SortedMap<String, Object> props = new TreeMap<String, Object>();
            props.put("basedir", FileSystemUtilities.getCanonicalPath(getProject().getBasedir()));

            for (Map.Entry<Object, Object> current : System.getProperties().entrySet()) {
                props.put("" + current.getKey(), current.getValue());
            }
            for (Map.Entry<String, Object> current : props.entrySet()) {
                builder.append("| [" + current.getKey() + "]: " + current.getValue() + "\n");
            }

            builder.append("|\n");
            builder.append("+=================== [End System properties]\n");

            // All done.
            getLog().debug(builder.toString().replace("\n", NEWLINE));
        }
    }
927295
public void setLogFileDir(String logDirName) {
        File logDir = new File(logDirName);
        if (!logDir.isAbsolute()) {
            logDir = new File(serverBaseDir, logDirName);
        }

        this.logFileDir = logDirName;
        if (started) {
            configuration.setLogFileDir(logDir.getAbsolutePath());
        }
    }
157229
def _determine_rotated_logfile(self):
        
        rotated_filename = self._check_rotated_filename_candidates()
        if rotated_filename and exists(rotated_filename):
            if stat(rotated_filename).st_ino == self._offset_file_inode:
                return rotated_filename

            # if the inode hasn't changed, then the file shrank; this is expected with copytruncate,
            # otherwise print a warning
            if stat(self.filename).st_ino == self._offset_file_inode:
                if self.copytruncate:
                    return rotated_filename
                else:
                    sys.stderr.write(
                        "[pygtail] [WARN] file size of %s shrank, and copytruncate support is "
                        "disabled (expected at least %d bytes, was %d bytes).\n" %
                        (self.filename, self._offset, stat(self.filename).st_size))

        return None
1167037
def _handle_log_rotations(self):
        '''  '''
        for h in self.capture_handlers:
            if self._should_rotate_log(h):
                self._rotate_log(h)
857728
public static synchronized LogStorage getLogStorage(){
        if(storage==null){
            String cls = Options.getStorage().getSystem("log.storageClass", LogStorage.class.getName());
            try{
                storage = (LogStorage)Class.forName(cls).newInstance();
            }catch (Exception e){
                throw S1SystemError.wrap(e);
            }
        }
        return storage;
    }
1075023
private File getSourceDirectory() throws IOException {
    File file = new File(source);
    if (!file.isDirectory()) {
      getLog().debug("Could not find directory at '" + source + "'");
    }
    return file.getCanonicalFile();
  }
678856
private void rotate() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, getFileName() + ": Rotating output log");
        }
        try {
            this.myChannel.close();
        } catch (IOException ioe) {
            FFDCFilter.processException(ioe, getClass().getName() + ".rotate", "424", this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(tc, getFileName() + ": Failed to close the output file; " + ioe);
            }
        }
        try {
            if (0 < getMaximumBackupFiles()) {
                // add the new backup file to the stored list
                addBackup();
            }
            this.myChannel = new FileOutputStream(this.myFile, true).getChannel();
        } catch (SecurityException se) {
            FFDCFilter.processException(se, getClass().getName() + ".rotate", "436", this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(tc, getFileName() + ": security error in rotate; " + se);
            }
        } catch (Throwable t) {
            FFDCFilter.processException(t, getClass().getName() + ".rotate", "441", this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(tc, getFileName() + ": error in rotate; " + t);
            }
        }
    }
726775
protected function rotateFiles()
	{
		$file=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
		$max=$this->getMaxLogFiles();
		for($i=$max;$i>0;--$i)
		{
			$rotateFile=$file.'.'.$i;
			if(is_file($rotateFile))
			{
				// suppress errors because it's possible multiple processes enter into this section
				if($i===$max)
					@unlink($rotateFile);
				else
					@rename($rotateFile,$file.'.'.($i+1));
			}
		}
		if(is_file($file))
		{
			// suppress errors because it's possible multiple processes enter into this section
			if($this->rotateByCopy)
			{
				@copy($file,$file.'.1');
				if($fp=@fopen($file,'a'))
				{
					@ftruncate($fp,0);
					@fclose($fp);
				}
			}
			else
				@rename($file,$file.'.1');
		}
		// clear stat cache after moving files so later file size check is not cached
		clearstatcache();
	}
823030
function storeDirectory(file) {
    var directory = file.fullParentDir;
    if (!watched_directories[directory]) {
      fs.stat(directory, function(err, stats) {
        if (err) {
          watched_directories[directory] = (new Date).getTime();
        } else {
          watched_directories[directory] = (new Date(stats.mtime)).getTime();
        }
      });
    }
  }
25074
public void writeToDisk() {
        if ( !initialized ) {
            initializeLog();
        }
        Writer writer = null;
        try {
            FileOutputStream fileOut = new FileOutputStream( this.fileName + (this.nbOfFile == 0 ? ".log" : this.nbOfFile + ".log" ),
                                                             true );
            writer = new OutputStreamWriter( fileOut,
                                             IoUtils.UTF8_CHARSET );
            final XStream xstream = createTrustingXStream();

            WorkingMemoryLog log = null;
            synchronized ( this.events ) {
                log = new WorkingMemoryLog(new ArrayList<LogEvent>( this.events ));
                clear();
            }
            writer.write( xstream.toXML( log ) + "\n" );
        } catch ( final FileNotFoundException exc ) {
            throw new RuntimeException( "Could not create the log file.  Please make sure that directory that the log file should be placed in does exist." );
        } catch ( final Throwable t ) {
            logger.error("error", t);
        } finally {
            if ( writer != null ) {
                try {
                    writer.close();
                } catch ( Exception e ) {
                }
            }
        }
        if ( terminate ) {
            closeLog();
            terminate = true;
        } else if ( split ) {
            closeLog();
            this.nbOfFile++;
            initialized = false;
        }
    }
352603
public final File getValidDirectory() {
		File file = this.directory;
		file = (file != null) ? file : getWarFileDocumentRoot();
		file = (file != null) ? file : getExplodedWarFileDocumentRoot();
		file = (file != null) ? file : getCommonDocumentRoot();
		if (file == null && this.logger.isDebugEnabled()) {
			logNoDocumentRoots();
		}
		else if (this.logger.isDebugEnabled()) {
			this.logger.debug("Document root: " + file);
		}
		return file;
	}
835900
public function getLogDir()
    {
        $home = getenv('HOME') ?: (getenv('HOMEDRIVE').DIRECTORY_SEPARATOR.getenv('HOMEPATH'));

        if (is_macos()) {
            $stateDir = getenv('XDG_STATE_HOME') ?: $home.'/Library';
            $stateDir .= '/Zephir/State';
        } elseif (is_windows()) {
            $stateDir = getenv('LOCALAPPDATA') ?: $home;
            $stateDir .= '\\Zephir\\State';
        } else {
            // See: https://stackoverflow.com/a/27965014/1661465
            $stateDir = getenv('XDG_STATE_HOME') ?: $home.'/.local/state';
            $stateDir .= '/zephir';
        }

        $path = $stateDir.DIRECTORY_SEPARATOR.Zephir::VERSION;
        if (!is_dir($path) && !mkdir($path, 0777, true) && !is_dir($path)) {
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $path));
        }

        return $path;
    }
1219392
static protected function is_log_dir_writable()
  {
    if (!is_writable(self::$log_dir))
      if (self::$to_stderr)
        error_log("Could't open " . self::$log_dir . " for writing. Does " . self::$log_dir . " exist? Permissions?");
  }
242420
def _should_rotate_log(self, handler):
        '''  '''
        if handler['rotate_log']:
            rotate_time_index = handler.get('rotate_log_index', 'day')
            try:
                rotate_time_index = self._decode_time_rotation_index(rotate_time_index)
            except ValueError:
                rotate_time_index = 2

            rotate_time_delta = handler.get('rotate_log_delta', 1)

            cur_t = time.gmtime()
            first_different_index = 9
            for i in range(9):
                if cur_t[i] != handler['log_rot_time'][i]:
                    first_different_index = i
                    break

            if first_different_index < rotate_time_index:
                # If the time deltas differ by a time step greater than what we
                # have set for the rotation (I.e., months instead of days) we will
                # automatically rotate.
                return True
            else:
                time_delta = cur_t[rotate_time_index] - handler['log_rot_time'][rotate_time_index]
                return time_delta >= rotate_time_delta

        return False
1077826
public String getLogLocation() {
        if (logInstanceBrowser instanceof MainLogRepositoryBrowserImpl) {
            return ((MainLogRepositoryBrowserImpl) logInstanceBrowser).getLocation().getAbsolutePath();
        } else {
            return ((OneInstanceBrowserImpl) logInstanceBrowser).getLocation().getAbsolutePath();
        }

    }