1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-27 09:51:12 +00:00

100 Commits

Author SHA1 Message Date
779f3bb81d Improve code documentation of Rackstash::Fields 2017-07-11 23:42:13 +02:00
a461b36b97 Allow to query and replace subarrays of Rackstash::Fields::Array 2017-07-11 23:42:13 +02:00
d07a9452f4 Add Rackstash::UNDEFINED constant
The {UNDEFINED} object can be used as the default value for method
arguments to distinguish it from `nil`. See
https://holgerjust.de/2016/detecting-default-arguments-in-ruby/#special-default-value
for details.
2017-07-11 23:42:13 +02:00
da1999dba3 Unify the conflict resolution behavior of merge! and deep_merge! in Rackstash::Fields::Hash
When setting `force: true` (the default), in both cases we not raise an
ArgumentError when setting a forbidden field and overwrite existing
fields. When setting it to `false`, we ignore forbidden or existing
fields in both cases.

We also allow a custom conflict resolution block to be passed to both
methods. In the case of deep_merge! and deep_merge, this applies to all
(potentially deeply nested) fields. Compatible objects, i.e. Hashes and
Arrays are still always merged without calling the block.
2017-07-11 22:23:19 +02:00
a0c92d57f8 Add File adapter to directly write to a local file 2017-07-10 23:45:02 +02:00
e96a0aaf94 Separate the PRERELEASE version part with a dash instead of a dot 2017-07-05 19:21:24 +02:00
d6c3111999 Always generate positive object IDs in inspect
Sometimes, object_ids are created as signed Integers which are invalid
in `inspect`. By using the default implementation of `Object#to_s`, we
can get valid object_ids the same way Ruby itself would have created
them.

For a motivation of this change, see

* https://bugs.ruby-lang.org/issues/13397
* https://github.com/ruby-concurrency/concurrent-ruby/pull/651
2017-07-03 13:37:05 +02:00
4eecc559a4 Transform list of forbidden_keys in Rackstash::Fields::Hash.new to a frozen Set
We then expose this frozen Set on the `forbidden_keys` attribute.
2017-06-30 19:27:46 +02:00
d26858c103 Add Rackstash::Fields::Array#size as an alias to length 2017-06-22 23:00:51 +02:00
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
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
f4e85f7013 Use a Concurrent::Hash instead of a Set for Fields::Tags
This makes the Rackstash::Fields::Tags class thread safe while still
mantaining its existing semantincs, given that Ruby's set is also build
on top of a simple Hash.
2017-06-16 23:04:54 +02:00
db8a5e50b5 Improve code documentation 2017-06-16 23:04:54 +02:00
1a73062758 Avoid Array instances when JSON'ifying Arrays / Hashes
Similar to the previous commit, we avoid the unnecessary allocation of
a temporary array when looping over the `@raw` value. In addition to
that, we ensure thread-safety by always operating on a copy of the raw
data so that other threads can not change anything under our feet
anymore.
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
da8904f412 Add a thread-safe Rackstash::Flows#each method 2017-05-09 22:20:23 +02:00
3a74701dd9 Add code documentation for Rackstash::Flows 2017-05-09 22:18:12 +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
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
3ccacfaab9 Move DEFAULT_OBJ_ID_STR_WIDTH to Rackstash module 2017-04-27 23:48:30 +02:00
a6c6fcc90b Protect the BufferStack with a Mutex 2017-04-27 22:05:40 +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
4bbbf25ef8 Use a Concurrent::Array for storing messages in the Buffer
This ensures that we can still concurrently add messages without messing
with the internal Array.
2017-04-27 21:49:36 +02:00
473618c479 Extract the SEVERITY_NAMES constant
This array lists the lowercase names of the supported severities which
can be set on the Logger.
2017-04-18 21:26:31 +02:00
7459a27a1c Explicitly name supported collection types during normalize
Since an AbstractCollection can in principal contain any raw value, we
want to make sure that we only handle known values. Others will probably
still be catched by the fallback converter calls at the bottom of
AbstractCollection#normalize.
2017-04-18 21:25:05 +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
dc9d553509 Display native-size object IDs in AbstractCollection#inspect 2017-04-06 23:09:22 +02:00
d9c7a2ad33 Add Fields::Array#push as an alias to #<< 2017-04-06 23:09:22 +02:00
7e452b630a Create new fields, tags and message objects on Buffer#clear
This helps in ensuring thread-safety when flushing unbuffered Buffers.
Previously, it was possibly for client code to still hold references to
fields on a flushed and cleared buffer, potentially resulting in
unintended side-effects if the client code was not aware that the buffer
was cleared.

By creating ompletely new object instances, existing references only
point to data from before the clear. This ensures a clean cut.
2017-04-06 23:09:16 +02:00
0edcce37c7 Use yield instead of to_proc in Hash#merge
This is functionally equivalent. However, the previous behavior resulted
in the block being materialized as a proc which is quite expensive, both
during materialization as well as when calling it. By using
`block_given?`, we can avoid this materialization.
2017-03-28 20:05:23 +02:00
16cb49c3f1 Improve method documentation on Fields::Hash 2017-03-07 16:45:47 +01: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
2070bf81a7 Move Fields::Hash#forbidden_key? into its correct alphabetical position 2017-03-07 14:52:12 +01:00
b2d2a89488 Make parameter documentation more exact 2017-02-18 22:40:36 +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
494b64c63a Remove redundant private method Rackstash::Fields::Array#new
The method is already provided by the parent class AbstractCollection
2017-02-16 23:04:57 +01:00
6958b8f509 Add Rubocop config and resolve most style issues 2017-02-16 22:47:17 +01:00