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
Log inside spec don't work in some cases #9462
Comments
These lines are problematic: Lines 290 to 302 in d08b646
|
You should be able to run the specs with |
Also, there is backend problem: require "log"
require "spec"
L = Log.for("spec")
L.backend = Log::IOBackend.new(File.open("/tmp/1.log", "a"))
L.level = Log::Severity::Info
it "1" do
L.info { "bla" }
1.should eq 1
end Log outputted to Stdout instead of file. WHY? |
Because when you include "spec" it configures the log with I don't understand why that code is there in spec. |
Personally I'm fine with this behavior. I'm more interested in the spec output than any interior logging, so the reduced noise is good when reviewing in the terminal or CI logs. Especially on other spec output formats ( Assuming we stick with it, I don't think its actually documented in the public Log or Spec docs? |
I think changing the behavior of Log just because you are requiring When I run specs in Ruby or Elixir, if the logger outputs to stdout, I see the output in stdout too. If I want to silence that I can configure it specifically in the But that's just my opinion. |
@z64 this is not about output something in specs. Main problem, when you test huge codebase which use logging pretty much, all outputted to stdout, which is not desired. |
@kostya if you want to test that the log are generated you can use Log.capture spec helper added in #9201 In #9145 we make the The You can configure additional logging in require "log"
require "spec"
Spec.before_suite do
backend = Log::IOBackend.new(File.open("/tmp/1.log", "a"))
Log.builder.bind("spec", :info, backend)
end
L = Log.for("spec")
it "1" do
L.info { "bla" }
1.should eq 1
end The stdout of the spec will be clean of los messages and the file will containt what you expect. |
I've run into this too now when updating a project to the new logging system. I wanted to hide the database logs from the specs and didn't understand why they are not removed by setting I think it's an unwanted behavior (I wouldn't want database logs in Rails tests for example), I guess it's fine if it's set to Anyway putting the code above into |
Log.error { "inside it does not work" }
won't run, all other runs fine.The text was updated successfully, but these errors were encountered: