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

218 Commits

Author SHA1 Message Date
43a303b09d Include Enumerable module into Flows 2017-12-20 21:27:12 +01:00
40e151ecb8 Rename the SkipEvent filter to DropIf to make the intention clearer 2017-12-20 18:41:40 +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
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
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
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
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
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
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
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
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
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
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
402f754736 Test TrucateMessage filter with Proc selectors and custom callables 2017-09-23 13:45:08 +02:00
f17692ff73 Add Update filter to set new values to existing event keys 2017-09-23 00:50:46 +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
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
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
74242caf0b There can be only one... UNDEFINED
By ensuring that we only ever create a single UNDEFINED object from the
UndefinedClass, it behaves more like nil
2017-09-07 21:18:03 +02:00
32e755396b Splat flows/adapters passed to Rackstash::Logger#initialize
This ensures that we are not unduely altering (i.e. flattening) adapter
specifications when creating the flows.
2017-08-31 21:59:48 +02:00
cadc235795 Add Helpers::Time module to access a monotonic clock 2017-08-30 01:01:15 +02:00
8b75013472 Test that the Lograge encoder skips messages 2017-08-24 23:17:20 +02:00
b101d7356a Add lograge encoder
This encoder formats logs similar to the key-value formatter of the
lograge gem.
2017-08-24 23:07:17 +02:00
40aa74c5c0 Always add a @timestamp field in the logstash encoder, even if it was removed by a filter 2017-08-24 23:07:17 +02:00
7b06d053ca Create an error event in the Flow exactly as a Buffer would
That way, we ensure that the error_flow receives an expected event and
doesn;t have to deal with different data formats which might result in
additional (then quietly hidden) errors.
2017-08-24 23:07:17 +02:00