1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

491 Commits

Author SHA1 Message Date
a475a5c6fc Use the ClassRegistry to register filters
This removes the requirement that filters need to be defined in the
Rackstash::Filters namespace in order to be usable with a short name.
Filters can be registered with an arbitrary name.

As before, raw blocks / procs can be defined as ad-hoc filters.
2017-12-20 23:40:20 +01:00
01593a9b8b Add Rackstash::ClassRegistry to register filters and encoders
Using the ClassRegistry, we can register short names for filter and
encoder classes so that they can be specified in a shorter and more
readable way during creation of the logger.
2017-12-20 23:06:25 +01:00
1b2dd09000 Add FilterChain#push as an alias to FilterChain#<< 2017-12-20 21:39:55 +01:00
0782f31d45 Test that FilterChain#append returns the original filter chain 2017-12-20 21:39:15 +01:00
6bfe8ecb25 Provide prepend alias for FilterChain@unshift
Ruby 2.5 introduces this alias for all arrays.
2017-12-20 21:33:49 +01:00
43a303b09d Include Enumerable module into Flows 2017-12-20 21:27:12 +01:00
ad4a40413b Add example to documentation of DropIf filter 2017-12-20 18:42:21 +01:00
40e151ecb8 Rename the SkipEvent filter to DropIf to make the intention clearer 2017-12-20 18:41:40 +01:00
3fabe95013 Refactor truncate_message filter
We extract some internal emthods to make the truncation flow clearer,
i.e. first we run the selectors, then we truncate the message, then we
insert the ellipsis message (if required).
2017-12-20 18:33:20 +01:00
1671b04dfb Add Fields::Hash#each and make the Hash class an Enumerable 2017-12-12 19:58:46 +01:00
e472b7fbce Add Fields::Hash#length to emulate Hash#length 2017-12-12 19:29:28 +01:00
d382a245f3 Add Fields::Hash#fetch to emulate Hash#fetch 2017-12-12 19:26:44 +01:00
9150b2e0ac Properly test every code path for Rackstash::Helpers::Time
Even if it doesn't look like it, there might (and in fact did) lure
unexpected errors even in seemlingly obvious code-paths.
2017-12-05 19:30:39 +01:00
6ce668e09d Allow to include the event's timestamp as a message tag in the Message encoder 2017-12-05 19:07:46 +01:00
2cb0d42408 Require rackstash in rackstash/rack
This allows users to just add

    require 'rackstash/rack'

in order to load thw whole Rackstash plus the Rack integration.
2017-12-05 18:59:56 +01:00
8cdd000b0c Allow to add error details with Logger#add_error 2017-12-05 18:59:21 +01:00
26597680af Set rack.errors in the Rack::Middlware
This ensures that other middlewares whi want to log to the default
rack.errors stream will log to a sensible location instead of the usual
default of raw STDOUT or STDERR.
2017-12-05 18:55:08 +01:00
3b8e76329c Explicitly load Rackstash::Version again during coverage tests 2017-11-29 12:16:47 +01:00
969e1e8cf3 Use a plain optional argument for normalize_timestamp 2017-11-14 08:56:02 +01:00
1552728971 Update Code of Conduct to v1.4 2017-10-27 20:12:41 +02:00
57119a3266 Rename the abstract adapter base class to BaseAdapter
This avoides the name clashes (and the resulting uncertanty with name
resolution) between the base class and its containing module.
2017-10-21 16:57:01 +02:00
d721c1fc72 Singularize the Filters module
Since we are using single objects from this namespaces, it is much
more suitable to be named in singular than in plural.
2017-10-21 16:38:07 +02:00
aa37d47b8f Singularize the Adapter and Encoder modules
Since we are using single objects from these namespaces, they are much
more suitable to be named in singular than in plural.
2017-10-20 22:27:50 +02:00
e857cdb9f1 Return an existing filter instance in Filters.build 2017-10-20 20:22:38 +02:00
8db2c917c2 Fix a couple of Rubocop warnings
All of these changes are either simple formatting changes or clarify
existing meaning. None of these changes affects externally visible
behavior.
2017-10-20 19:51:11 +02:00
126e510edc Require time helper on require 'rackstash/helpers' 2017-10-20 19:43:51 +02:00
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