Commit Graph

24 Commits

Author SHA1 Message Date
Michael Grosser
203998c916
allow running each test with pure ruby path/to/test.rb
also:
 - makes test dependencies obvious
 - makes tests runnable from within subfolders
2019-12-18 08:49:19 -06:00
George Claghorn
75a53297c7
Add ActionController::Base.log_at
Allow setting a different log level per request.
2019-09-24 13:47:34 -04:00
George Claghorn
d41e282a94 Prefer assert_not_includes 2019-09-13 13:56:12 -04:00
George Claghorn
ffc8475db8
Fix setting a more verbose thread-local log level
We prepend a check against the thread-local level to Logger#add, but because it proceeds to check against the thread-global level, only setting a quieter thread-local level works. The quietest of the two wins. Fix by reimplementing #add entirely.

It's unfortunate to have to do this, but I've already patched upstream Logger to prefer the level instance method over the @level instance variable, so we'll be able to avoid touching #add at all in the future. See https://github.com/ruby/logger/pull/41.
2019-09-13 13:54:18 -04:00
Senya
56ec504db6 Make ActiveSupport::Logger Fiber-safe
Use Fiber.current.__id__ in ActiveSupport::Logger#local_level= in order
to make log level local to Ruby Fibers in addition to Threads.
2019-07-24 22:42:24 +03:00
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
bogdanvlviv
ee6bbe403c
Add missing require
`activesupport/test/logger_test.rb` requires `tmpdir`.

`activesupport/test/multibyte_test_helpers.rb` requires
`filutils`, `open-uri`, and `tmpdir`.
2018-06-07 15:34:30 +03:00
Koichi ITO
ac717d65a3 [Active Support] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
Kir Shatrov
72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Matthew Draper
3420a14590 Merge pull request #29540 from kirs/rubocop-frozen-string
Enforce frozen string in Rubocop
2017-07-02 01:11:50 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Pat Allan
036bdee4d5 Make ActiveSupport frozen string literal friendly.
The ActiveSupport test suite only passes currently if it uses the latest unreleased commits for dalli, and a patch for Builder:
https://github.com/tenderlove/builder/pull/6

Beyond that, all external dependencies (at least, to the extent they’re used by ActiveSupport) are happy, including Nokogiri as of 1.8.0.
2017-06-20 18:04:44 +10:00
Michael Grosser
a9aed2ac94
improve error message when include assertions fail
assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message

assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
2016-09-16 12:03:37 -07:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Xavier Noria
a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Rafael Mendonça França
1de3db9046
Make sure the yielded variable is the logger 2016-06-10 13:30:50 -04:00
Kevin McPhillips
83f9cdb02a Be explicit about what Logger class is expected 2016-06-09 22:11:07 -04:00
Piotr Jakubowski
2518bda97c Fix logger silencing for broadcasted loggers
Fix #23609

Commit 629efb6 introduced thread safety to logger silencing but it
didn't take into account the fact that the logger can be extended with
broadcasting to other logger.

This commit introduces local_level to broadcasting Module which enables
broadcasted loggers to be properly silenced.
2016-02-11 21:00:51 +01:00
schneems
3d10d9d6c3 [close #22917] Don't output to STDOUT twice
When `rails console` or `rails server` are used along with a logger set to output to `STDOUT` then the contents will show up twice. This happens because the logger is extended with `ActiveSupportLogger.broadcast` with a destination of STDOUT even if it is already outputting to `STDOUT`.

Previously PR #22592 attempted to fix this issue, but it ended up causing NoMethodErrors. A better approach than relying on adding a method and flow control is to inspect the log destination directly. For this `ActiveSupport::Logger.logger_outputs_to?` was introduced

```ruby
logger = Logger.new(STDOUT)
ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
# => true
```

To accomplish this we must look inside of an instance variable of standard lib's Logger `@logdev`. There is a related Ruby proposal to expose this method in a standard way: https://bugs.ruby-lang.org/issues/11955
2016-01-06 09:55:35 -06:00
Carl P. Corliss
629efb6057 Fixes LoggerSilence#silence threadsafety
- uses instance defined level if no custom local log level defined
- Keeps track of local log level per [ thread + object-instance ]
- prevents memory leakage by removing local level hash key/value on #silence method exit
- avoids the use of Thread local variables
2015-12-23 12:57:33 -05:00
David Heinemeier Hansson
f914454f3a Add ActiveSupport::Logger#silence that works the same as the old Logger#silence extension 2012-12-21 19:15:36 +01:00
Arun Agrawal
27a8e693da no more deprecation required. 2012-03-31 23:00:13 +05:30
Arun Agrawal
6a240826ca No more BufferedLogger so it can be LoggerTest 2012-03-31 22:49:15 +05:30