1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-01-05 13:41:29 +00:00

315 Commits

Author SHA1 Message Date
c1e3c99ab5 Do not write empty lines to IO and File adapters
If a line is completely empty, it is not useful to log it at all since
it would be invisible on the created logstream anyway. If we get passed
an empty String from the encoder, we can thus silently ignore it.
2017-10-19 23:06:45 +02:00
ca685bb13b Do not prefix an empty messages with tags
If an event's message is completely empty (usually because there was
nothing logged at all), it isn't very useful to output this bare marked
up message at all. We thus ignore it and pass it along unchanged in the
Message encoder.

Note that we still add tags for messages consisting of other whitespace
like e.g. a newline added from a formatted empty message added to a
Logger.
2017-10-19 23:03:48 +02:00
bded98fb6e Fix spelling in description of Rack::Middleware 2017-10-18 19:17:14 +02:00
c58c70febb Add Rack middleware
The middleware can be used in a Rack appliction wrap all log messages
emitted to the logger during a single request in a single emitted log
event. This ensures that all data concerning the request, including log
messages as well as additional fields and tags are logged as one single
event.

This ensures that the data is kept as a whole when the log event is
handled by later systems like Logstash. Each request can be analyzed as
a whole without having to group or parse complex multi-line log formats.
2017-10-18 00:21:43 +02:00
cb95c0b0e4 Add new data-only buffering mode to Buffer
With this, the Buffer knows three buffering modes:

* :full - This is the same as the previous buffering-enabled mode. With
  this, we buffer everything and never auto-flush
* :none - the previous non-buffering mode. We autoflush everytime there
  is a new messase or explicitly added fields. All stored data is
  cleared afterwards.
* :data - the new mode. It behaves almost like :none with the notable
  exception that we retain fields and tags after the auto flush.

The new mode is especially useful to emulate a regular Logger even when
using per-request buffers. With that, you can add fields once to a
buffer. Each time a message is added, it will be flushed directly
without waiting for the request to be finished. Yet, the flows can still
take advantage of all the previously added fields and tags to properly
format the emitted log event.
2017-10-17 23:31:13 +02:00
224a87f677 Run coverage tests on the latest MRI Ruby on Travis CI 2017-10-17 19:10:43 +02:00
81fc2f46fa Remove explicit JDK version from .travis.yml
We can just use the default, currently openjdk8, the same version we
previously selected manually.
2017-10-17 19:08:02 +02:00
6bdd4d12aa Don't explicitly require 'rational' to normalize fields
The rational implementation will be laoded automatically by Ruby.
Attempting to load rational.rb (in Ruby 2.1) will cause unintended
consequences for the whole running program.
2017-10-10 23:56:46 +02:00
29733e4617 Move coveralls test dependency to gemspec and update it 2017-10-10 21:44:12 +02:00
2175f2f759 Remove redcarpet dependency from Gemfile 2017-10-10 21:36:54 +02:00
c651acb136 Fix yard tags in several filters 2017-10-10 21:30:35 +02:00
2e5c39d5d0 Add filters to add default fields or tags to an event 2017-10-10 21:30:35 +02:00
fa73e63a3e Allow to freeze and dup Rackstash::Flows collections 2017-10-10 20:40:29 +02:00
e62af8b1cf Fix warning in spec for Adapters::Logger
This fizes a Ruby warning generated when running the tests for
Rackstash::Adaptes::Logger. The warning was:

> warning: instance variable @closed not initialized
2017-10-10 20:32:29 +02:00
9af991392c Load documentation.rb early in a yard run
This allows us to use the doc macros contained in that file everywhere
without having to worry about load order.
2017-10-10 11:27:32 +02:00
3c27f2ae70 Remove Rackstash::Sink
The Sink was a vehicle to transport some shared state between the logger
instance and the buffers, most notably the default fields and default
tags.

It turns out however, that error handling during merging of the
default_fields and default_tags is non trivial since there, the buffer
is in sime kind of limbo: users won't write to it anymore (and thus
don't expect exceptions there) while the error handling of the
individual flows is not yet reached. Since users can specify procs in
default_fields, they can still raise for whatever user-defined reason.

Luckily, the insertion of default fields and default tags can easily be
done by a filter later anyway, under the protection of the flow's error
handling in Flow#write. This allows us just remove the whole concept of
the sink and just pass the Flows object to the Buffer.

Not having to merge default_fields during event creation significantly
simplifies Buffer#to_event which was rather ugly to begin with but now
turned out quite beatifully.
2017-10-10 11:27:32 +02:00
72dae8e222 Clarify the behavior of Fields::Hash#set with different force values 2017-10-08 21:54:32 +02:00
2d0f47a813 Do not rescue exceptions on Proc normalization
Rescuing exceptions here would mask errors and make debugging realy hard
when setting e.g. default fields.
2017-10-08 21:35:51 +02:00
b64823170f Add Rackstash::Flow.error_flow= as a real setter
We now also allow to explicitly set the local error_flow of an
individual flow to nil to force it to use the global
Rackstash.error_flow again.
2017-10-08 13:12:23 +02:00
e532be28c3 Add Rackstash::Flow.encoder= as a real setter 2017-10-08 13:11:11 +02:00
469ab5823a Correctly describe the proc evaluation behavior in Fields 2017-10-06 22:23:14 +02:00
2e7083218c Add Hash encoder which normalizes the raw event hash to a JSON-compatible Hash 2017-10-05 23:16:27 +02:00
b6d15a8da7 Extract resolving of severity values to Rackstash.severity 2017-10-05 21:17:32 +02:00
c371e072c5 Add param name to documentation of Encoders::Message#initialize 2017-10-05 01:10:35 +02:00
4ee34e5d4e Insert an ellipsis if messages are removed in TruncateMessage filter
If messages are removed by the final cut step (but not when applying the
selectors), we insert an ellipsis, by default a Message with the
contents of "[...]\n", at the place where we removed messages. This
helps the investigating human who reads the logs to understand that
there were logs messages removed from the event.
2017-10-05 01:05:55 +02:00
37c85ec038 Add code example how to instantiate the ClearColor filter 2017-10-03 22:53:26 +02:00
e7fd3677ca Ensure more consistent code formatting with Rubocop 2017-10-03 22:52:49 +02:00
d157e53129 Add logger adapter to write log events to an external logger 2017-10-03 20:25:30 +02:00
0941b24b63 Optionally prefix all message lines with extraced fields in Message encoder
This can be used to achieve similar results as
ActiveSupport::TaggedLogger. With our implementation, the "tags" are
prepended to each line (instead of each message) and we add the same
tags to all message lines.

If required, you can still use ActiveSupport::TaggedLogger with
Rackstash to add tags at the time of adding the log message.
2017-09-30 00:01:25 +02:00
3584244bc1 Return the normalized unchanged message from the Message encoder 2017-09-29 23:40:02 +02:00
59c94a8ecc Insert newline comment below magic comments in ruby file header 2017-09-29 17:15:07 +02:00
a4c80fd15f Require Rename and Replace filters with all other filters 2017-09-28 21:30:02 +02:00
807460b585 Fix typos in code comments 2017-09-28 21:27:31 +02:00
402f754736 Test TrucateMessage filter with Proc selectors and custom callables 2017-09-23 13:45:08 +02:00
f8d8c040d5 Optimize the TruncateMessage filter with Proc selectors
If we have a proc, we can pass it directly to the `select!` method
instead of having to manually call the selector. This gives a
significant speedup for the common case of simple selectors:

    require 'benchmark/ips'
    Benchmark.ips do |x|
      selector = ->(value) { value < 500 }
      values = (1..1000).to_a

      x.report("call") { values.select { |v| selector.call(v) } }
      x.report("block") { values.select(&selector) }

      x.compare!
    end

    Warming up --------------------------------------
                    call   663.000  i/100ms
                   block     1.598k i/100ms
    Calculating -------------------------------------
                    call      6.897k (± 4.8%) i/s -     34.476k in   5.011617s
                   block     16.561k (± 4.2%) i/s -     83.096k in   5.026999s

    Comparison:
                   block:    16560.7 i/s
                    call:     6896.5 i/s - 2.40x  slower
2017-09-23 01:16:27 +02:00
3db9041ab4 Use the short filter syntax in the TruncateMessage example 2017-09-23 01:16:27 +02:00
f17692ff73 Add Update filter to set new values to existing event keys 2017-09-23 00:50:46 +02:00
d66408d333 Fix typos and omissions in the documentation of the Replace filter 2017-09-23 00:40:40 +02:00
c383e2b3dc Add Replace filter to set new values on event fields 2017-09-23 00:26:03 +02:00
a827769bb3 Add Rename filter to rename event fields 2017-09-23 00:14:56 +02:00
0ab79e56c0 Clarify that re-raised exceptions are also logged in a Flow 2017-09-22 23:22:31 +02:00
6a45a8586d Remove "@api private" tag from Flow#write documentation
Any public method is part of the public interface of the class and thus
needs to be equally well supported. Only because methods are not usually
called by end-users, we still need to properly document, test, and check
them.
2017-09-22 23:20:12 +02:00
1711b0d589 Resolve Ruby warning in spec for Rackstash::Encoders::Logstash
This resolves the following warning:

> spec/rackstash/encoders/logstash_spec.rb:18: warning: ambiguous first
> argument; put parentheses or a space even after `/' operator
2017-09-21 22:35:35 +02:00
2f0755c967 Optionally retain scope when evaluating procs in collections
This allows to receive the scope as the argument to a proc-value instead
of always executing the proc in the scope's context.
2017-09-21 22:30:52 +02:00
bcc481bfbe Test that a Logger can be created without defining flows 2017-09-21 22:29:39 +02:00
20e3f28273 Return the given value on Flows#[]= 2017-09-21 22:27:13 +02:00
14479e97dd Avoid creating additional array instance on Flows#to_ary 2017-09-21 22:26:27 +02:00
060c4f3e8b Fix comment typo 2017-09-21 22:23:06 +02:00
070df582e7 Describe how to create a Logger instance 2017-09-21 16:21:40 +02:00
a31f07f7c2 Yield the last created flow on Logger.new
This allows to configure the last (and often only) flow on creation of
the Logger without having to manually create the object. We can thus use
the following shortcut to e.g. set a custom encoder:

    Rackstash::Logger.new(STDOUT) do
      encoder Rackstash::Encoder::Message.new
    end
2017-09-21 16:18:46 +02:00