Removing logs from tests

There is much logging going on and I find it helpful, but not when I run my tests. Is there a way to suppress those logs in testing environment? I tried to set level in config/environments/test.rb like this:
config.log_level = :error
but this doesn’t do anything, and then I tried this:
config.logger = Logger.new('/dev/null')
but it seems too much and it still leaves message “INFO: Not on AWS Lambda. In local mode perform_later executes the job with perform_now instead.” which looks out of place in test output.
Is there any way of intercepting logs in tests?

Currently, believe there are some puts in Jets code. So there’s no quick and easy way to remove the annoying output. It annoys me also, would like to make it removable.

Will try to take a look as part of the next Jets big release, which is getting closer. Will also review and consider PRs. At least, wanted to provide a response.

Thanks for responding, I’ll try and contribute PR if I get some free time these days.

1 Like

I can’t find any instructions for sending PRs and I would like to send one to deal with this issue if it’s ok.

This was actually fixed in Jets 5

Also, here are some instructions for PRs Contributing to Jets - Jets Ruby Serverless Framework

I’m running 5.0.0 and it’s not really improved. This is the code if I’m not mistaken:

      def perform_later(meth, event={}, context={})
        if on_lambda?
          function_name = "#{self.to_s.underscore}-#{meth}"
          call = Jets::Commands::Call::Caller.new(function_name, JSON.dump(event), invocation_type: "Event")
          call.run
        else
          puts "INFO: Not on AWS Lambda. In local mode perform_later executes the job with perform_now instead."
          perform_now(meth, event, context)
        end
      end

and this is how I would change it:

      def perform_later(meth, event={}, context={})
        if on_lambda?
          function_name = "#{self.to_s.underscore}-#{meth}"
          call = Jets::Commands::Call::Caller.new(function_name, JSON.dump(event), invocation_type: "Event")
          call.run
        else
          puts "INFO: Not on AWS Lambda. In local mode perform_later executes the job with perform_now instead." unless testing?
          perform_now(meth, event, context)
        end
      end
    ...

      def testing?
        ENV['RAILS_ENV'] == 'test'
      end

:man_facepalming:t2:Oh I thought this thread was about the rspec testing helpers.

This is more general, or maybe it’s more specifically about the .perform_later.

Instead of if testing? would probably change the puts use the Jets.logger.info. Believe that’s it.

Will consider and review PRs for this. Of course, no sweat either way. Thanks.

1 Like

Submitted and you already merged. Great experience even with this small contribution. Thanks!

1 Like