ActiveSupport::Notifications render.active_model_serializers

Squashed commits:

Add Logging

Generates logging when renders a serializer.

Tunning performance on notify_active_support

- Use yield over block.call
- Freeze the event name string

Organize the logger architeture

* Keep only the `ActiveModel::Serializer.logger` to follow the same public API we
  have for example to config, like `ActiveModel::Serializer.config.adapter` and
  remove the `ActiveModelSerializers.logger` API.
* Define the logger on the load of the AMS, following the Rails convention on
  Railties [1], [2] and [3].

This way on non Rails apps we have a default logger and on Rails apps we will
use the `Rails.logger` the same way that Active Job do [4].

[1]: 2ad9afe4ff/activejob/lib/active_job/railtie.rb (L9-L11)
[2]: 2ad9afe4ff/activerecord/lib/active_record/railtie.rb (L75-L77)
[3]: 2ad9afe4ff/actionview/lib/action_view/railtie.rb (L19-L21)
[4]: 2ad9afe4ff/activejob/lib/active_job/logging.rb (L10-L11)

Performance tunning on LogSubscriber#render

Move the definition of locals to inside the `info` block this way the code is
executed only when the logger is called.

Remove not needed check on SerializableResource

Use SerializableResource on ActionController integration

On the ActionController was using a adapter, and since the instrumentation is
made on the SerializableResource we need to use the SerializableResource over
the adapter directly. Otherwise the logger is not called on a Rails app.

Use SerializableResource on the ActionController, since this is the main
interface to create and call a serializer.

Using always the SerializableResource we can keep the adapter code more easy to
mantain since no Adapter will need to call the instrumentation, only the
SerializableResource care about this.

Add docs about logging

Add a CHANGELOG entry

Keep the ActiveModelSerializers.logger

Better wording on Logging docs

[ci skip]

Add doc about instrumentation

[ci skip]

Use ActiveModel::Callbacks on the SerializableResource
This commit is contained in:
Mauro George
2015-10-21 20:12:47 -02:00
committed by Benjamin Fleischer
parent efe5128a2e
commit 51424963da
10 changed files with 183 additions and 1 deletions

View File

@@ -9,6 +9,8 @@ This is the documentation of AMS, it's focused on the **0.10.x version.**
- [Getting Started](general/getting_started.md)
- [Adapters](general/adapters.md)
- [Configuration Options](general/configuration_options.md)
- [Logging](general/logging.md)
- [Instrumentation](general/instrumentation.md)
## How to

View File

@@ -0,0 +1,18 @@
# Instrumentation
AMS uses the instrumentation API provided by Active Support this way we
can choose to be notified when AMS events occur inside our application.
## render.active_model_serializers
|key | value |
|-------------|----------------------|
|:serializer | The serializer class |
|:adapter | The adapter instance |
```ruby
{
serializer: PostSerializer,
adapter: #<ActiveModel::Serializer::Adapter::Attributes:0x007f96e81eb730>
}
```

12
docs/general/logging.md Normal file
View File

@@ -0,0 +1,12 @@
# Logging
If we are using AMS on Rails app by default the `Rails.logger` will be used.
On a non Rails enviroment by default the `ActiveSupport::TaggedLogging` will be
used.
If we need to customize the logger we can define this in an initializer:
```ruby
ActiveModel::Serializer.logger = Logger.new(STDOUT)
```