Otherwise if a different supervisor implementation,
such as a `ConsumerSupervisor` in GenStage, pass a
different name by accident, logging would fail.
Closes#8126.
Regexes used to be precompiled to binary values during code
compilation. These binary values may be incompatible with
different operating systems and OTP releases. That's why
an explicit `Regex.recompile/1` or `Regex.recompile!/1` was
required.
Regexes now fallback to binary matching if the precompiled
binary is not compatible with the runtime version.
Previous logger versions would always compute the mode on the Logger
handler which meant that, if any other Logger handler blocked, either because
it was waiting on IO, the system is overloaded or due to long computations, a
burst of messages could make the Logger message queue grow quite large
until it notices it should change its mode.
This commit changes the computation to use a counter which is offset by
the current message length queue. This makes the following script go from
tens of thousands messages in the Logger inbox to only hundreds (assuming
a `sync_threshold` of 100) when writing a rate limited stdio with
`mix run foo.exs | pv -p -L 1k 1>/dev/null`:
```elixir
require Logger
# monitor memory
# :observer.start()
defmodule Loop do
def run() do
Logger.info(inspect(:crypto.strong_rand_bytes(1024)))
Process.sleep(10)
run()
end
end
for _i <- 1..100 do
spawn(fn ->
Loop.run()
end)
end
defmodule OtherLoop do
def run() do
IO.inspect(:stderr, Process.info(Process.whereis(Logger), :message_queue_len), [])
IO.inspect(:stderr, :ets.tab2list(Logger.Config), [])
Process.sleep(100)
run()
end
end
OtherLoop.run()
```
Otherwise it is impossible to dynamically remove them,
which partially defeats the point of adding them dynamically
in the first place.
Therefore this commit moves the whole dynamic backend
management to the user.
Closes#8213
`Logger.add_backend/1,2` and `Logger.remove_backend/1,2` are specced
to only allow atoms as backends, while `Logger.configure_backend/2`
allows backend to be of the more general `backend` type. But both
`add_backend` and `remove_backend` work fine with the more generic
`backend` type, so the specs should be extended to cover that type.
The specs were introduced with c24a13ebf8, while the spec for
`configure_backends` was introduced in aeefd59b15 (with a small fix in
b98421fe51).
Now that we support a more general `compile_time_purge_matching`,
we can deprecate `compile_time_purge_level`. We chose the name
`:level_lower_than` rather than `:level` for the matching key
since all other matches are exact.
This means that the arguments won't be evaluated if the
message has a lower level than the logger one or if the
logger mode is set to discard.
Closes#7046.