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(); }
private TailerListener createListener() { return new TailerListenerAdapter() { @Override public void fileRotated() { // ignore, just keep tailing } @Override public void handle(String line) { session.getAsyncRemote().sendText(line); } @Override public void fileNotFound() { session.getAsyncRemote().sendText(new FileNotFoundException(logFile.toString()).toString()); } @Override public void handle(Exception ex) { session.getAsyncRemote().sendText(ex.toString()); } }; }
/** * 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); } }
public void tail(TailerListener listener) { File file = new File( fileLocation); Tailer tailer = Tailer.create(file, listener, 10); tailer.run(); }
public void tail(TailerListener listener, String alias) { File file = logLookup.map(l -> l.lookup(alias)) .orElse(new File( fileLocation)); Tailer tailer = Tailer.create(file, listener, 10); tailer.run(); }
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(); } }
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); } }); }
/** * Creates a Tailer for the given file, with a specified buffer size. * * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param bufSize Buffer size */ public GzipTailer(File file, TailerListener listener, long delayMillis, boolean end, int bufSize) { super(file, listener, delayMillis, end, bufSize); this.file = file; this.delayMillis = delayMillis; this.end = end; this.inbuf = new byte[bufSize]; // Save and prepare the listener this.listener = listener; listener.init(this); }
public void start() { for (Log log : logs) { TailerListener listener = new MyTailerListener(log); executor.execute(new Tailer(log.getFile(), listener, DELAY, false, false)); } }
@Autowired public LogTailer(File file, TailerListener listener, long delayMillis) { super(file, listener, delayMillis, TAIL_FROM_END_OF_FILE); }
private void setupTailer() { TailerListener listener = new LogTailer(); File tailFile = new File(DebugLogger.LOGGING_FILENAME); tailer = Tailer.create(tailFile, new LogTailer(), 500, true); }
public GzipTailer(final File file, final TailerListener listener, final long delayMillis, final boolean end, final boolean reOpen) { this(file, listener, delayMillis, end); }
public GzipTailer(final File file, final TailerListener listener, final long delayMillis, final boolean end, final boolean reOpen, final int bufSize) { this(file, listener, delayMillis, end, bufSize); }
/** * Creates and starts a Tailer for the given file. * * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param bufSize buffer size. * @return The new tailer */ public static GzipTailer create(File file, TailerListener listener, long delayMillis, boolean end, int bufSize) { GzipTailer tailer = new GzipTailer(file, listener, delayMillis, end, bufSize); Thread thread = new Thread(tailer); thread.setDaemon(true); thread.start(); return tailer; }
/** * Creates a Tailer for the given file, starting from the beginning, with the default delay of 1.0s. * * @param file The file to follow. * @param listener the TailerListener to use. */ public GzipTailer(File file, TailerListener listener) { this(file, listener, DEFAULT_DELAY_MILLIS); }
/** * Creates a Tailer for the given file, starting from the beginning. * * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. */ public GzipTailer(File file, TailerListener listener, long delayMillis) { this(file, listener, delayMillis, false); }
/** * Creates a Tailer for the given file, with a delay other than the default 1.0s. * * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. */ public GzipTailer(File file, TailerListener listener, long delayMillis, boolean end) { this(file, listener, delayMillis, end, DEFAULT_BUFSIZE); }
/** * Creates and starts a Tailer for the given file with default buffer size. * * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @return The new tailer */ public static GzipTailer create(File file, TailerListener listener, long delayMillis, boolean end) { return create(file, listener, delayMillis, end, DEFAULT_BUFSIZE); }
/** * Creates and starts a Tailer for the given file, starting at the beginning of the file * * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @return The new tailer */ public static GzipTailer create(File file, TailerListener listener, long delayMillis) { return create(file, listener, delayMillis, false); }
/** * Creates and starts a Tailer for the given file, starting at the beginning of the file * with the default delay of 1.0s * * @param file the file to follow. * @param listener the TailerListener to use. * @return The new tailer */ public static GzipTailer create(File file, TailerListener listener) { return create(file, listener, DEFAULT_DELAY_MILLIS, false); }