1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-24 16:31:13 +00:00

68 Commits

Author SHA1 Message Date
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
f6453e0f47 Replace overwritten conversion methods with implicit method to retain expected method behavior 2017-02-16 21:55:30 +01:00
b9a1b0c386 Clarify how the scope parameter works on field methods 2017-02-16 20:53:41 +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
b14f7a95af Clarify that all field methods accepting values can also accept Proc 2017-02-16 20:38:25 +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
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
5fc679a63a Document additional public methods 2017-02-10 23:48:49 +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
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
52645e67ac Refer to Rackstash::SEVERITIES in Logger#add method docs only
There is no explicit need to repeat the constants here.
2017-02-08 00:00:42 +01:00
eea88db9a8 Document return value of BufferStack#flush_and_pop 2017-02-07 23:59:40 +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
fdb3565d85 Add documentation for Rackstash::Fields::Hash 2017-02-07 00:13:05 +01:00
c260d9b154 Don't refer to the (non-existing yet) rack middleware in the docs 2017-02-05 21:21: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
d78739d7d4 Improve documentation of Buffer and BufferStack 2017-02-04 01:02:38 +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
e842d5c771 Automatically flush and clear a non-buffering Buffer after adding a message 2017-02-03 19:06:39 +01:00
cb4cdadd95 Add Buffer#flush to flush the current Buffer to the Sink 2017-02-03 19:05:44 +01:00
95c8b8f8fb Pass the sink from the Logger to each individual Buffer 2017-02-03 18:43:34 +01:00
bfe4cc854a Add Rackstash::Buffer#buffering? flag
Generally, a non-buffering Buffer will eventually be flushed to the sink
after each logged message. This thus mostly resembles the way
traditional loggers work in Ruby. A buffering Buffer however holds log
messages, fields and tags for a longer time. Only at a specific time,
all log messages and stored fields will be flushed to the Sink as a
single log event. A common scope for such an event is a full request to
a Rack app.
2017-02-03 14:54:50 +01:00
5e37df77e5 Add Rackstash::Buffer#clear to clear all data in a buffer 2017-02-03 14:21:22 +01:00
8d2ea04c4f Set a timestamp on the Buffer 2017-02-03 00:28:45 +01:00
551b75c65d Add fields and tags to the Buffer
Each buffer instance can hold messages, fields and tags. These together
form the log event which will eventually be written to the log target.

By adding fields and tags, you can add highly details structured
information to your logs which allow to filter and analyze the logs
without having to parse complex multi-line logs.
2017-02-02 23:55:02 +01:00
95bf8430a9 Ignore blank tags 2017-02-02 23:45:24 +01:00
e9c98fc648 Allow to pass a scope with procs when merging Tags 2017-02-02 23:39:40 +01:00
0292a7eacb Resolve class ambiguity in Hash and Array constructors 2017-02-02 23:03:53 +01:00