Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to Tail to disable splitting on newline #12

Closed
ghost opened this issue Jun 25, 2012 · 0 comments
Closed

Add config option to Tail to disable splitting on newline #12

ghost opened this issue Jun 25, 2012 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 25, 2012

I'm writing a script that'll tail a file and email me the changes to the file once a minute (if there are any). Right now, FileWatch::Tail splits new data by line. I'd like to add an open to FileWatch::Tail called :split_lines that gives you the option of splitting lines or not. It would default to true to keep existing behavior. It'd be something like this:

diff --git a/lib/filewatch/tail.rb b/lib/filewatch/tail.rb
index 0bce046..7424ac8 100644
--- a/lib/filewatch/tail.rb
+++ b/lib/filewatch/tail.rb
@@ -32,6 +32,7 @@ module FileWatch
         :stat_interval => 1,
         :discover_interval => 5,
         :exclude => [],
+        :split_lines => true
       }.merge(opts)
       @watch.exclude(@opts[:exclude])

@@ -138,8 +139,12 @@ module FileWatch
         begin
           data = @files[path].sysread(4096)
           changed = true
-          @buffers[path].extract(data).each do |line|
-            yield(path, line)
+          if @opts[:split_lines]
+            @buffers[path].extract(data).each do |line|
+              yield(path, line)
+            end
+          else
+            yield(path, data)
           end

           @sincedb[@statcache[path]] = @files[path].pos

I'd be happy to issue a pull request for that. I can also write tests for it to make sure that it doesn't break anything. If I do that, should I just use mintiest like you use on logstash?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant