Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ActiveModelSerializers.logger with default null device #1089

Merged
merged 1 commit into from
Sep 15, 2015

Conversation

bf4
Copy link
Member

@bf4 bf4 commented Aug 28, 2015

Based on a discussion in the amserializers slack
It's not used anywhere in this PR, but it could be...

@joaomdmoura
Copy link
Member

I don't remember this @bf4 can you refresh me? 😄

@bf4 bf4 mentioned this pull request Sep 7, 2015
@bf4
Copy link
Member Author

bf4 commented Sep 10, 2015

ref: https://amserializers.slack.com/archives/general/p1440623581000150

beauby [4:13 PM]
What's the preferred way to log stuff from AMS?

joaomdmoura [4:14 PM]
I think do no logging right now, what is the specifics?

beauby [4:15 PM]
@joaomdmoura: Adding the warning when hitting a resource without a defined serializer

joaomdmoura [4:15 PM]
you can have some method the tries to use rails log, if it does not find it then use a fallback

beauby [4:16 PM]
rails uses ruby's Logger class, no?

joaomdmoura [4:16 PM]
I think so, but I’m not sure if it implements something useful on top of it

joaomdmoura [4:17 PM]
I think it also enables you can change what to log and where, so would be nice to use it

beauby [4:17 PM]
Nah, I just checked it, the ActiveSupport extension doesn't add much

joaomdmoura [4:17 PM]
really?

beauby [4:18 PM]
Yeah, it does add a method to silence a given level

joaomdmoura [4:18 PM]
well if that is the case then we case use ruby one, just maek sure to share what you found on the PR so we can check it as well

beauby [4:18 PM]
but the levels are defined in ruby core anyways

bf4 [4:18 PM]
rails uses a buffered logger or whatever

beauby [4:18 PM]
http://guides.rubyonrails.org/active_support_core_extensions.html#extensions-to-logger

bf4 [4:18 PM]
just

  class Serializer
   WINDOZE  = /win(32|64)/ =~ RUBY_PLATFORM
  DEV_NULL = (WINDOZE ? 'nul'      : '/dev/null')
  # example code. do not use
  @@logger = Rails.logger || Logger.new(DEV_NULL)
  def self.logger
    @@logger
  end

this is what I did in metric_fu https://github.com/metricfu/metric_fu/blob/194f401fc0a0fdef71354de5d133260813e791de/lib/metric_fu/logger.rb for a custom logger (edited)

beauby [4:23 PM]
thanks @bf4, I'll look into it

bf4 [4:23 PM]
what you'd really want to do is probably have it default to dev/null, but in the rails engine, have an initializer that sets it to Rails.logger or something custom

beauby [4:24 PM]
@bf4: Hmm why /dev/null instead of stderr?

bf4 [4:25 PM]
oh, because it's super annoying to have output you're not interested int, and STDOUT and STDERR do that.. logs/ams.log could grow too big. I've never gotten built-in log-rotation to work

bf4 [4:25 PM]
especially in tests

beauby [4:27 PM]
Hmm but if you log to /dev/null by default, how is anyone ever going to see it?

bf4 [4:29 PM]
it's opt-in unless it's integrated with Rails, in which case it's configurable

bf4 [4:30 PM]
so, the most common use-cases are covered.

bf4 [4:30 PM]
with Rails, you'd probably want to use the TaggedLogger if available so we can tag it as coming from AMS. There's probably a good example of this somewhere out there

@bf4
Copy link
Member Author

bf4 commented Sep 10, 2015

Also, ref: #1099 (comment)

# railtie
    initializer 'active_job.logger' do
      ActiveSupport.on_load(:active_job) { self.logger = ::Rails.logger }
    end

# https://github.com/rails/rails/blob/7a3ca69959e312a215d5e8144fca79a08654fd89/activejob/lib/active_job/base.rb


    ActiveSupport.run_load_hooks(:active_job, self)

@beauby
Copy link
Contributor

beauby commented Sep 12, 2015

This would be cool, so that we could log stuff such as:

  • trying to include an undefined relationship (for instance when misspelling author with authr and such)
  • trying to serialize a related resource for which there exists no serializer (which currently outputs the whole jsonified object)

@NullVoxPopuli
Copy link
Contributor

👍

NullVoxPopuli added a commit that referenced this pull request Sep 15, 2015
Add ActiveModelSerializers.logger with default null device
@NullVoxPopuli NullVoxPopuli merged commit 1bff617 into rails-api:master Sep 15, 2015
joaomdmoura added a commit that referenced this pull request Sep 15, 2015
Rubocop fixes for issues introduced by #1089
@bf4 bf4 deleted the add_logger branch June 14, 2016 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants