当前位置: 首页>>代码示例>>Java>>正文


Java Tailer类代码示例

本文整理汇总了Java中org.apache.commons.io.input.Tailer的典型用法代码示例。如果您正苦于以下问题:Java Tailer类的具体用法?Java Tailer怎么用?Java Tailer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Tailer类属于org.apache.commons.io.input包,在下文中一共展示了Tailer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startTailingLog

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private void startTailingLog() {
  TailerListener listener = new TailerListenerAdapter() {
    @Override
    public void handle(String line) {
      System.out.println(testName + ": " + line);
    }
  };

  // Tail the log
  File file = new File(getBasedir() + File.separator + getLogFileName());
  try {
    if (file.exists()) {
      file.delete();
    }
    file.createNewFile();
  } catch (IOException e) {
    e.printStackTrace();
  }
  Tailer tailer = new Tailer(file, listener, TAIL_DELAY_MILLIS);
  Thread thread = new Thread(tailer);
  thread.setDaemon(true);
  thread.start();
}
 
开发者ID:GoogleCloudPlatform,项目名称:app-maven-plugin,代码行数:24,代码来源:TailingVerifier.java

示例2: registerLogFileTailThreads

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private void registerLogFileTailThreads() throws IOException {
    final Collection<String> outputFileNames = new HashSet<>();
    final Collection<Appender> loggerAppenders = this.loggerContext.getConfiguration().getAppenders().values();
    loggerAppenders.forEach(appender -> {
        if (appender instanceof FileAppender) {
            outputFileNames.add(((FileAppender) appender).getFileName());
        } else if (appender instanceof RandomAccessFileAppender) {
            outputFileNames.add(((RandomAccessFileAppender) appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            outputFileNames.add(((RollingFileAppender) appender).getFileName());
        } else if (appender instanceof MemoryMappedFileAppender) {
            outputFileNames.add(((MemoryMappedFileAppender) appender).getFileName());
        } else if (appender instanceof RollingRandomAccessFileAppender) {
            outputFileNames.add(((RollingRandomAccessFileAppender) appender).getFileName());
        }
    });

    outputFileNames.forEach(s -> {
        final Tailer t = new Tailer(new File(s), new LogTailerListener(), 100, false, true);
        final Thread thread = new Thread(t);
        thread.setPriority(Thread.MIN_PRIORITY);
        thread.setName(s);
        thread.start();
    });
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:LoggingOutputSocketMessagingController.java

示例3: startTailingFile

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
/**
 * Starts tailing the given file, thus updating the log lines in the table.
 *
 * @param file
 *         the file to tail
 *
 * @throws FileNotFoundException
 *         if the file was not found
 */
public void startTailingFile(File file) throws FileNotFoundException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getAbsolutePath());
    }
    closeCurrentFile();
    config.getState().addToRecentFiles(file.getAbsolutePath());
    logTailListener = new BufferedLogTailListener(columnizer.getValue(), columnizedLogs,
            config.getPreferences().getLogBufferSize());
    logTailListener.skipEmptyLogsProperty().bind(config.getPreferences().skipEmptyLogsProperty());
    logTailListener.limitNumberOfLogsProperty().bind(config.getPreferences().limitNumberOfLogsProperty());
    logTailListener.maxNumberOfLogsProperty().bind(config.getPreferences().maxNumberOfLogsProperty());
    tailer = Tailer.create(file, logTailListener, config.getPreferences().getTailingDelayInMillis());
    tailingFile.set(true);
    tailedFileName.set(file.getAbsolutePath());
}
 
开发者ID:joffrey-bion,项目名称:fx-log,代码行数:25,代码来源:MainController.java

示例4: CsvStreamReader

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
/**
 * Creates a CsvStreamReader with supplied separator and quote char.
 *
 * @param source The file to an underlying CSV source
 * @param separator The delimiter to use for separating entries
 * @param quoteChar The character to use for quoted elements
 * @param escape The character to use for escaping a separator or quote
 * @param line The line number to skip for start reading
 * @param strictQuotes Sets if characters outside the quotes are ignored
 * @param ignoreLeadingWhiteSpace If true, parser should ignore
 *  white space before a quote in a field
 */
private CsvStreamReader(Source source, char separator, char quoteChar,
    char escape, int line, boolean strictQuotes,
    boolean ignoreLeadingWhiteSpace) {
  super(new StringReader("")); // dummy call to base constructor
  contentQueue = new ArrayDeque<>();
  TailerListener listener = new CsvContentListener(contentQueue);
  tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY,
      false, true, 4096);
  this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes,
      ignoreLeadingWhiteSpace);
  this.skipLines = line;
  try {
    // wait for tailer to capture data
    Thread.sleep(DEFAULT_MONITOR_DELAY);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:CsvStreamReader.java

示例5: LogTailer

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
protected LogTailer(File toRead, long timeForFileToBeCreated) throws IOException {
    long requiredTime = System.currentTimeMillis() + timeForFileToBeCreated;
    while ((System.currentTimeMillis() < requiredTime) && !(toRead.exists() && toRead.canRead())) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            // ignore
        }
    }
    if (!toRead.exists() || !toRead.canRead()) {
        throw new IllegalStateException("Couldn't read "+toRead.getCanonicalPath()+" in the configured timeout");
    }
    logger.debug("Initialising Tailer for "+toRead.getCanonicalPath());

    tailer = new Tailer(toRead, this, DELAY, false);
}
 
开发者ID:betfair,项目名称:cougar,代码行数:17,代码来源:LogTailer.java

示例6: testShouldBeCallListenerHandleByLogging

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
@Test
public void testShouldBeCallListenerHandleByLogging() throws Exception {
    Tailer.create(TestFileLoader.load("data/tailer/test.log"), listener, 100, true);

    ConcurrentTestFileWriter.writeTestData("data/tailer/test.log", "logging", 3);

    Thread.sleep(300);
    verify(mockCollector, times(3)).collect(anyString());
}
 
开发者ID:geminiKim,项目名称:logregator,代码行数:10,代码来源:TailCollectorCollectorTest.java

示例7: open

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public void open(Map stormConf) {
  fileToParseName = fileToParse.getAbsolutePath();
  parsedLineQueue = new LinkedBlockingQueue<Map>(maxQueueSize);
  currentLine = 0;

  if (lineParser == null)
    lineParser = new NoOpLogLineParser();

  tailer = Tailer.create(fileToParse, this, tailerDelayMs);
  log.info("Started tailing "+fileToParseName);
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:12,代码来源:FileTailingDataProvider.java

示例8: run

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public void run() {
  if (!fileToParse.isFile()) {
    log.warn("Skipping " + fileToParse.getAbsolutePath() + " because it doesn't exist anymore!");
    return;
  }

  lineNum = 0;
  batchOfDocs.clear();
  startMs = System.currentTimeMillis();

  if (logIndexer.tail) {
    tailer = new Tailer(fileToParse, this, logIndexer.tailerDelayMs);
    log.info("Tailing "+fileToParse+" with delay "+logIndexer.tailerDelayMs+" ms");

    logIndexer.tailerReaperBgThread.trackTailer(this);

    tailer.run(); // we're already in a thread, so just delegate to run
    log.info("Tailer stopped ... LogParser for " + fileName + " is done running.");
    logIndexer.onFinishedParsingFile(fileName, lineNum, skippedLines, System.currentTimeMillis() - startMs);
  } else {
    try {
      doParseFile(fileToParse);
    } catch (Exception exc) {
      log.error("Failed to process file '" + fileName + "' due to: " + exc, exc);
    }
  }
}
 
开发者ID:lucidworks,项目名称:fusion-log-indexer,代码行数:28,代码来源:LogIndexer.java

示例9: tail

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public void tail(TailerListener listener) {

        File file = new File(
                             fileLocation);
        Tailer tailer = Tailer.create(file, listener, 10);

        tailer.run();
    }
 
开发者ID:aol,项目名称:micro-server,代码行数:9,代码来源:LogTailer.java

示例10: TailService

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
@Autowired
public TailService(@Value("${geoip2.cityfile}") String cityFile,
		@Value("${access.logs}") String accessLogs, EventMessenger eventMessenger) {
	this.eventMessenger = eventMessenger;

	String databaseFile = cityFile;
	if (databaseFile != null) {
		Path database = Paths.get(databaseFile);
		if (Files.exists(database)) {
			try {
				this.reader = new DatabaseReader.Builder(database.toFile()).build();
			}
			catch (IOException e) {
				LoggerFactory.getLogger(getClass()).error("GeoIPCityService init", e);
			}
		}
	}

	this.tailers = new ArrayList<>();

	for (String logFile : accessLogs.split(",")) {
		Path p = Paths.get(logFile.trim());
		this.tailers.add(new Tailer(p.toFile(), new ListenerAdapter()));
	}

	this.executor = Executors.newFixedThreadPool(this.tailers.size());
	for (Tailer tailer : this.tailers) {
		this.executor.execute(tailer);
	}
}
 
开发者ID:ralscha,项目名称:wampspring-demos,代码行数:31,代码来源:TailService.java

示例11: preDestroy

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
@PreDestroy
public void preDestroy() {
	if (this.tailers != null) {
		for (Tailer tailer : this.tailers) {
			tailer.stop();
		}
	}

	if (this.executor != null) {
		this.executor.shutdown();
	}
}
 
开发者ID:ralscha,项目名称:wampspring-demos,代码行数:13,代码来源:TailService.java

示例12: initNetlogTailer

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private void initNetlogTailer() {
    
    if (netLogTailerThread != null) {
        netLogTailerThread.interrupt();
        netLogTailerThread = null;
    }
    
    if (activeNetLogFile != null) {
        TailerListener listener = new NetLogTailerListener();
        Tailer tailer = new Tailer(activeNetLogFile, listener, 2000);
        this.netLogTailerThread = new Thread(tailer);
        netLogTailerThread.setDaemon(true);
        netLogTailerThread.start();
    }
}
 
开发者ID:jrosocha,项目名称:jarvisCli,代码行数:16,代码来源:LogFileService.java

示例13: getStream

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public Observable<String> getStream(final long pollIntervalMs) {
	return Observable.create(new OnSubscribeFunc<String>() {

		@Override
		public Subscription onSubscribe(
				final Observer<? super String> observer) {
			TailerListener listener = createListener(observer);
			final Tailer tailer = new Tailer(file, listener, pollIntervalMs);
			Thread t = new Thread(createRunnable(observer, tailer));
			t.start();
			return createSubscription(tailer);
		}
	});
}
 
开发者ID:davidmoten,项目名称:websockets-log-tail,代码行数:15,代码来源:FileTailer.java

示例14: createRunnable

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private Runnable createRunnable(final Observer<? super String> observer,
		final Tailer tailer) {
	return new Runnable() {
		@Override
		public void run() {
			try {
				tailer.run();
			} catch (Exception e) {
				observer.onError(e);
			}
		}
	};
}
 
开发者ID:davidmoten,项目名称:websockets-log-tail,代码行数:14,代码来源:FileTailer.java

示例15: createSubscription

import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private Subscription createSubscription(final Tailer tailer) {
	return new Subscription() {
		@Override
		public void unsubscribe() {
			tailer.stop();
		}
	};
}
 
开发者ID:davidmoten,项目名称:websockets-log-tail,代码行数:9,代码来源:FileTailer.java


注:本文中的org.apache.commons.io.input.Tailer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。