/*
@Override public String getLogFilePid(File file) { return ""; }
513204
@Override
	public long getLogFileTimestamp(File file) {
		String name = file.getName();
		// Check name for extension
		if (name == null || name.length() == 0 || !name.startsWith(TEXTLOGPREF) || !name.endsWith(TEXTLOGEXT)) {
			return -1L;
		}
		long result = -1L;
		try {
			Date date = DATEFORMAT.parse(name.substring(TEXTLOGPREF.length(), name.length() - TEXTLOGEXT.length()));
			result = date.getTime();
		} catch (ParseException ex) {
			// Fall through to return -1L;
		}
		return result;
	}
970724
static String getVersionForFile(final File file)  {
        try {
            final PluginMeta pluginMeta = loadMeta(file);
            return pluginMeta.getVersion();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
180726
LogFileHeader logFileHeader() throws InternalLogException
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "logFileHeader", this);

        // Check that the file is actually open
        if (_activeFile == null)
        {
            if (tc.isEntryEnabled())
                Tr.exit(tc, "logFileHeader", "InternalLogException");
            throw new InternalLogException(null);
        }

        final LogFileHeader logFileHeader = _activeFile.logFileHeader();

        if (tc.isEntryEnabled())
            Tr.exit(tc, "logFileHeader", logFileHeader);
        return logFileHeader;
    }
212294
private void padFile(FileOutputStream out) throws IOException {
        currentSize = Util.padLogFile(out, currentSize, preAllocSize);
    }
1328049
private static String getFileExtension(Resource file) {
	String name = file.getName();
	String[] arr;
	try {
	    arr = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(name, '.'));
	}
	catch (PageException e) {
	    arr = null;
	}
	if (arr.length < 2) return "";

	return arr[arr.length - 1];
    }
1193905
public static FileInputStream getFileIputStream(final File file) throws FileNotFoundException {
        try {
            return AccessController.doPrivileged(
                                                 new PrivilegedExceptionAction<FileInputStream>() {
                                                     @Override
                                                     public FileInputStream run() throws FileNotFoundException {
                                                         return new FileInputStream(file);
                                                     }
                                                 });
        } catch (PrivilegedActionException e) {
            // Creating a FileOutputStream can only return a FileNotFoundException
            throw (FileNotFoundException) e.getCause();
        }
    }
216968
public void dumpLogBuffer(String identifier)
  {
    final ArrayList<LogRecord> logBufferCopy;
    final PrintWriter logDumper;
    final OutputStream outStream;
    Formatter formatter = this.getFormatter();

    // Check if compression of dump file is enabled
    boolean disableCompression =
        System.getProperty(DISABLE_DUMP_COMPR_PROP) != null;

    // If no identifying factor (eg, an incident id) was provided, get one
    if (identifier == null)
    {
      identifier = EventUtil.getDumpFileId();
    }

    // Do some sanity checking to make sure we're not flooding the user's
    // disk with dump files
    cleanupSfDumps(true);

    String logDumpPath = logDumpPathPrefix + "/" + LOG_DUMP_FILE_NAME +
                         identifier + LOG_DUMP_FILE_EXT;

    if (!disableCompression)
    {
      logDumpPath += LOG_DUMP_COMP_EXT;
    }

    logger.debug("EventHandler dumping log buffer to {}", logDumpPath);

    // Copy logBuffer because this is potentially long running.
    synchronized (this)
    {
      logBufferCopy = new ArrayList<>(logBuffer);
      logBuffer.clear();
    }

    File outputFile = new File(logDumpPath);

    /**
     * Because log files could potentially be very large, we should never open
     * them in append mode. It's rare that this should happen anyways...
     */
    try
    {
      // If the dump path doesn't already exist, create it.
      if (outputFile.getParentFile() != null)
      {
        outputFile.getParentFile().mkdirs();
      }

      outStream = disableCompression ?
                  new FileOutputStream(logDumpPath, false) :
                  new GZIPOutputStream(new FileOutputStream(logDumpPath, false));

      logDumper = new PrintWriter(outStream, true);
    }
    catch (IOException exc)
    {
      // Not much to do here, can't dump logs so exit out.
      logger.debug("Log dump failed, exception: {}", exc.getMessage());

      return;
    }

    // Iterate over log entries, format them, then dump them.
    for (LogRecord entry : logBufferCopy)
    {
      logDumper.write(formatter != null ? formatter.format(entry) :
                      entry.getMessage());
    }

    // Clean up
    logDumper.flush();
    logDumper.close();
  }
73909
private static function getPid()
    {
        if (!is_file(self::$pidFile)) {
            return 0;
        }

        $pid = intval(file_get_contents(self::$pidFile));
        return $pid;
    }
931819
private static void writePid(String file, boolean ignorePidFile) {
      File pidFile = new File(file);
      if(pidFile.exists()) {
        Long oldPid = getPid(pidFile);
        if(oldPid==null) {
          pidFile.delete();
        } else {
          log.warn("\n\t==================================\n\tThe OpenTSDB PID file [" + file + "] already exists for PID [" + oldPid + "]. \n\tOpenTSDB might already be running.\n\t==================================\n");
          if(!ignorePidFile) {
            log.warn("Exiting due to existing pid file. Start with option --ignore-existing-pid to overwrite"); 
            System.exit(-1);
          } else {
            log.warn("Deleting existing pid file [" + file + "]");
            pidFile.delete();
          }
        }
      }
      pidFile.deleteOnExit();
      File pidDir = pidFile.getParentFile();
      FileOutputStream fos = null;
      try {
        if(!pidDir.exists()) {
          if(!pidDir.mkdirs()) {
            throw new Exception("Failed to create PID directory [" + file + "]");
          }
        }     
        fos = new FileOutputStream(pidFile);      
        String PID = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
        fos.write(String.format("%s%s", PID, EOL).getBytes());
        fos.flush();
        fos.close();
        fos = null;
        log.info("PID [" + PID + "] written to pid file [" + file + "]");
      } catch (Exception ex) {
        log.error("Failed to write PID file to [" + file + "]", ex);
        throw new IllegalArgumentException("Failed to write PID file to [" + file + "]", ex);
      } finally {
        if(fos!=null) try { fos.close(); } catch (Exception ex) { /* No Op */ }
      }
    }
670685
private String getLogFolderPath() {

        String path = null;
        if (OpenCms.getRunLevel() >= OpenCms.RUNLEVEL_3_SHELL_ACCESS) {
            path = new File(OpenCms.getSystemInfo().getLogFileRfsPath()).getParent();
            // making sure the path ends with the file separator CHAR
            if ((path != null) && !path.endsWith(File.separator)) {
                path += File.separator;
            }

        }
        return path;
    }
340671
private long getPreviousSegmentId(File file) {
        PbdSegmentName segmentName = PbdSegmentName.parseFile(m_usageSpecificLog, file);
        if (segmentName.m_result != PbdSegmentName.Result.OK) {
            throw new IllegalStateException("Invalid file name: " + file.getName());
        }
        return segmentName.m_prevId;
    }
175544
private static int port(final File file) throws Exception {
        while (!file.exists()) {
            TimeUnit.MILLISECONDS.sleep(1L);
        }
        final int port;
        try (InputStream input = Files.newInputStream(file.toPath())) {
            // @checkstyle MagicNumber (1 line)
            final byte[] buf = new byte[10];
            while (true) {
                if (input.read(buf) > 0) {
                    break;
                }
            }
            port = Integer.parseInt(
                new TrimmedText(new Utf8String(buf)).asString()
            );
        }
        return port;
    }
380599
public String getLogFileName()
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass
                        , "getLogFileSize"
                            );

        String logFileName = objectManagerState.logFileName;

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass
                       , "getLogFileSize"
                       , new Object[] { logFileName });
        return logFileName;
    }
454414
SimpleLog getLastLog() throws IOException {
    if (logFiles.isEmpty()) {
      return null;
    }
    return new SimpleLog(logFiles.get(logFiles.size() - 1));
  }
810280
private File calculateLogFile(long timestamp) {
		if (ivSubDirectory == null)
			getControllingProcessDirectory(timestamp, svPid) ;
		
		return getLogFile(ivSubDirectory, timestamp);
	}
247744
private void handleLogfile() {
        if (args.logFile != null) {
            FileUtils.close(out);
            FileUtils.close(err);
        }
    }
1207057
public function getLogs($file)
    {
        $pattern = "/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/";

        $log_levels = $this->getLevels();

        // There has GOT to be a better way of doing this...
        preg_match_all($pattern, $file, $headings);
        $log_data = preg_split($pattern, $file);

        $log = [];
        foreach ($headings as $h) {
            for ($i = 0, $j = count($h); $i < $j; $i++) {
                foreach ($log_levels as $ll) {
                    if (strpos(strtolower($h[$i]), strtolower('.' . $ll))) {
                        $log[] = ['level' => $ll, 'header' => $h[$i], 'stack' => $log_data[$i]];
                    }
                }
            }
        }

        $log = array_reverse($log);

        return $log;
    }