Skip to content

Instantly share code, notes, and snippets.

@magnuspalmer
Created March 7, 2015 08:40
Show Gist options
  • Save magnuspalmer/8925492eb4a51f97d7d4 to your computer and use it in GitHub Desktop.
Save magnuspalmer/8925492eb4a51f97d7d4 to your computer and use it in GitHub Desktop.
Groovy tail -f using Apache Commons IO
@Grapes([
@Grab(group='commons-io', module='commons-io', version='2.4'),
@Grab('log4j:log4j:1.2.17')
])
import org.apache.commons.io.input.*
import org.apache.log4j.*
import groovy.util.logging.*
@Log4j
class MyTailerListener extends TailerListenerAdapter {
void handle(String line) {
println line;
}
void fileRotated() {
log.info "File is rotated."
}
}
File logFile = new File("/var/logs/iibtest.log")
TailerListener listener = new MyTailerListener()
Tailer.create(logFile, listener)
@magnuspalmer
Copy link
Author

Read more about other options on running the Tailer in the JavaDocs
http://commons.apache.org/proper/commons-io/javadocs/api-2.4/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment