jstirk / tail_from_sentinel Goto Github PK
View Code? Open in Web Editor NEWReads a file, but only returns content once a marker (sentinel) has been found.
Reads a file, but only returns content once a marker (sentinel) has been found.
TailFromSentinel Parses a file, looking for a sentinel line that satisfies a block, and returns all lines from there until the end of the file (including the sentinel itself). This can be handy when you are looking for information in a log file only after a certain condition (eg. a date) has been met. You can either use it on it's own, or subclass it to build your own custom tail-like classes. Standalone: File.open('/var/log/messages', 'r') do |file| tfs=TailFromSentinel::Base.new(file) { |line| line =~ /Dec 20 11:2\d+/ } end tfs.data # => [ 'Dec 20 11:20:00 ...', 'Dec 20 11:21:00 ...', ... ] Subclassed: class TailMyFile < TailFromSentinel::Base DATA_ROOT="/path/to/data/" def initialize(data_file) file=File.open(File.join(DATA_ROOT, data_file), 'r') do |file| super(file, &select_sentinel_criteria(data_file)) end end def select_sentinel_criteria(data_file) case data_file when ''production.log' Proc.new { |line| line =~ /pattern/ } when 'development.log' Proc.new { |line| line =~ /another pattern/ } else raise "Unhandled file: #{data_file}" end end end t=TailMyFile.new('production.log') t.data # => [ 'Started GET "/pattern ...", " Processing ... ", ... ]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.