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

279 Commits

Author SHA1 Message Date
7c0c983dc2 Add Message encoder to just log the log message
This encoder is useful for local consumption of the raw log stream, e.g.
during development where the developer might not care for any additional
fields. With this encoder, the log output can mostly resemble a "classic"
line-based log feed.
2017-06-21 01:38:11 +02:00
e29c8976bb Clarify that the JSON encoder strips all whitespace 2017-06-21 01:38:11 +02:00
32b3ef8e0e Add Rackstash::Fields::Array#pop
This method does exactly the same as `::Array#pop`
2017-06-21 01:38:11 +02:00
649de80698 Allow multiple arguments to Rackstash::Fields::Array#push
We now also support the new alias to `Array#push` called `append` which
will be added to the core `Array` with Ruby 2.5.
2017-06-21 01:38:11 +02:00
6eccf6cc37 Don't copy or alter frozen UTF-8 strings in fields
With this, we optimize the common case where we do have valid UTF-8
strings to begin with. If the given String is already frozen, as is
common for e.g. Hash keys, we don't even need to create a new object.

With this change, we also always return frozen strings from
`Rackstash::Fields::AbstractCollection#utf9_encode`. This avoids an
unecessary object copy when inserting it in a Hash and still ensures
that values are always frozen anyway.
2017-06-21 01:38:11 +02:00
aad1660135 Add Callable adapter to handle a log in a custom way
Users can provide a "callable", i.e. a proc or block which will be
called for each written log. This allows users to custom handle the
logs without having to write a full adapter.

Usually, users should still write a full adapter to handle all cases of
their wrapped log device.
2017-06-21 01:38:11 +02:00
0aa39483dd Add Raw encoder which just passes the log event 2017-06-16 23:04:55 +02:00
16d76a7217 Allow to automatically flush the IO adapter after each write 2017-06-16 23:04:55 +02:00
00786283f0 Add IO adapter
This adapter allows to write newline-separated log lines to an existing
IO object, e.g. STDOUT. It does not allow to reopen the IO device.
2017-06-16 23:04:55 +02:00
b3f9a63253 Allow to define a suitable default encoder per adapter
The global default (unless overwritten by an adapter class) is to use
the JSON encoder since it's the most versatile and flexible option for a
logger today.
2017-06-16 23:04:55 +02:00
bf178ef36d Add JSON encoder 2017-06-16 23:04:54 +02:00
05f0faeedc Add abstract adapter and adapter registry
An ada pert wraps a log device (e.g. a file, an underlying logger, ...)
and provides an uniform interface to write the encoded log event to its
final target.

By using a registry, we can create the required adapter instance for a
provided log device automatically.
2017-06-16 23:04:54 +02:00
da3113e880 Avoid Array instances when normalizing Arrays / Hashes
`each_with_object` allocates an array for each kv pair. Switching to
the slightly more verbose but less allocatey `each_pair` eliminates
array allocations.

This follows the similar change in Rails:
960de47f0e
2017-05-23 13:27:22 +02:00
7ffdc527af Ensure we are only adding actual Flow objects in Rackstash::Flows.new 2017-05-09 22:22:25 +02:00
54c10a0576 Improve code formatting in specs for Rackstash::Flows 2017-05-09 22:21:19 +02:00
da8904f412 Add a thread-safe Rackstash::Flows#each method 2017-05-09 22:20:23 +02:00
335bbe0064 Test the correct alias-methods for Flows#to_ary and Flows#to_a 2017-05-06 23:49:51 +02:00
eb6cb29440 Return only present flows from Flows#to_ary 2017-05-06 23:49:05 +02:00
b2c1a1da0e Rename Target(List) to Flow(s)
Since a flow will significantly affect the representation of a log event
over its life before being persistet by the final adapter, the new term
better reflects what it is responsible for.

It also helps to avoid the dupliction of meaning between Sink, Target,
Adapter.
2017-05-06 14:47:40 +02:00
ec30779429 Remove unused variable in specs 2017-05-04 21:40:23 +02:00
5f68082810 Add Rackstash::TargetList to hold a list of defined log targets
The TargetList behaves mostly like an array which ensures that all its
elements are Targets.
2017-04-27 23:49:56 +02:00
2b0de27956 Return nil on BufferStacl#flush_and_pop
The buffer should not be reused after a flush anyway. By not returning
it, we ensure that it does not leak outside.
2017-04-27 22:04:13 +02:00
0026cdb204 Format the message string in the Logger
Since the Message class now formats the passed message on initialization
anyways, there is no need anymore to retain the formatter there.
Instead, we can just format the message string in the Logger before
creating the Message instance.

This significantly simplifies the Message class and better encapsulates
the knowledge about the line formatter into the Logger class.
2017-04-18 21:25:05 +02:00
f3f6fba89b Format the passed message on Message initialization
Since we can not guarantee that a user-supplied formatter is side-effect
free, a delayed formatting might result in unexpected results. An
example of such a formatter is the one used by
ActiveSupport::TaggedLogging.
2017-04-13 17:42:28 +02:00
d9c7a2ad33 Add Fields::Array#push as an alias to #<< 2017-04-06 23:09:22 +02:00
bfa5e33c04 Add Fields::Hash#reverse_merge and reverse_merge! similar to the ActiveSupport methods on Hash 2017-03-07 16:45:47 +01:00
22d1cdb646 Add Rackstash::Fields::Hash#deep_merge! and deep_merge
These methods are useful convenience methods to add (nested) fields to a
hash while optionally retaining existing values. Usually, `#deep_merge!`
or `#set` will be the commonly used ways to set fields to a hash.
2017-02-18 22:36:21 +01:00
4a185096d6 Add Rackstash::Fields::Hash#key? predicate 2017-02-18 01:15:49 +01:00
e13efe5ed3 Add consistent hash method to Rackstash::Fields::AbstractCollection
This follows the rule that two objects which are eql? also have the same
hash value. It is also required to ensure that we can use collections in
sets, hashes and arrays where the hash-equality is checked for certain
operations.
2017-02-17 19:12:47 +01:00
411465073f Check code coverage of tests using coveralls 2017-02-16 23:26:24 +01:00
0339d4bced Test Rackstssh::Fields::AbstractCollection#clone 2017-02-16 23:08:42 +01:00
6958b8f509 Add Rubocop config and resolve most style issues 2017-02-16 22:47:17 +01:00
2cff0cb5fa Improve code formatting 2017-02-16 20:54:11 +01:00
057cf2c8f7 Add Rackstash::Fields::Array#merge and #merge! which work similar to the union operator 2017-02-16 20:50:38 +01:00
890b193234 Add basic array operations to Rackstash::Fields::Array 2017-02-16 01:14:20 +01:00
c401a29ab3 Allow to specify a custom scope in Rackstash::Fields::Array#concat 2017-02-16 00:41:40 +01:00
8232d139f4 Add specs for handling of nested procs inside arrays with fields 2017-02-16 00:39:08 +01:00
bd376af884 Use thread-safe raw objects for field hashes and arrays 2017-02-14 22:47:55 +01:00
3ec21e7646 Always resolve procs when setting them into fields 2017-02-13 23:37:02 +01:00
ad038f4317 Add Rackstash::Fields::Array#<< to add a value at the end of the array 2017-02-10 23:22:41 +01:00
ebd2a19251 Test that Logger#add sets the current formatter on the message 2017-02-09 23:31:48 +01:00
68a2b57e28 Add Logger#<< to ad a raw unformatted message to the buffer
If the current Buffer is bufering, the message will just be added. Else,
it will be flushed to the sink directly.
2017-02-09 14:13:31 +01:00
031198cf14 Add Hash#set to set a field from a block if it doesn't exist yet
This allows to define default values for certain fields which can be
inserted just before a Buffer is flushed. They won;t overwrite prior
user-provided fields.

Through the use of a block, expensive calculations for a field could be
avoided if the field is not going to be inserted, e.g. because it exists
already or is forbidden from being set.
2017-02-09 00:15:18 +01:00
62dea60216 Add a more specific test name 2017-02-08 00:02:22 +01:00
2e39d6f007 Add Logger#with_buffer to add a new buffering buffer to the stack 2017-02-07 23:39:06 +01:00
6667c06519 Add Logger#fields and Logger#tags for direct access to the current Buffer's fields and tags 2017-02-07 23:39:06 +01:00
d489b6e26a Ensure Rackstash::FIELD_* constants are frozen strings 2017-02-05 21:18:32 +01:00
728ac29432 Allow to push and pop new Buffers on the BufferStack 2017-02-04 01:19:56 +01:00
3078c7d4ca Use a different BufferStack per thread
That way, we can ensure that the BufferStack and the Buffers themselves
including their nested fields can not be accessed by different threads,
providing some thread safety for non malicious users.
2017-02-04 01:04:21 +01:00
83d82fada4 Replace spiked BufferStack#with_buffer with BufferStack#current
Using a block here is unnecessary and doesn't help us with any
thread-safty guarantees on deeply nested fields or tags. Thus, we can
just remove this and replace it with a simpler method returning the
top-most buffer.

When using this buffer, we still have to ensure that only a single
Thread can access it.
2017-02-04 00:18:27 +01:00