@@ -13,7 +13,7 @@ defmodule Logger do
13
13
to avoid clogging logger backends.
14
14
15
15
* Alternates between sync and async modes to remain
16
- performant when required but also apply back-pressure
16
+ performant when required but also apply back-pressure
17
17
when under stress.
18
18
19
19
* Wraps OTP's `error_logger` to prevent it from
@@ -244,7 +244,6 @@ defmodule Logger do
244
244
"""
245
245
@ spec level ( ) :: level
246
246
def level ( ) do
247
- check_logger!
248
247
% { level: level } = Logger.Config . __data__
249
248
level
250
249
end
@@ -365,19 +364,23 @@ defmodule Logger do
365
364
Use this function only when there is a need to log dynamically
366
365
or you want to explicitly avoid embedding metadata.
367
366
"""
368
- @ spec log ( level , IO . chardata | ( ( ) -> IO . chardata ) , Keyword . t ) :: :ok
367
+ @ spec log ( level , IO . chardata | ( ( ) -> IO . chardata ) , Keyword . t ) :: :ok | { :error , :not_available }
369
368
def log ( level , chardata , metadata \\ [ ] ) when level in @ levels and is_list ( metadata ) do
370
- check_logger!
371
369
% { mode: mode , truncate: truncate ,
372
370
level: min_level , utc_log: utc_log? } = Logger.Config . __data__
373
371
374
372
if compare_levels ( level , min_level ) != :lt do
375
373
tuple = { Logger , truncate ( chardata , truncate ) , Logger.Utils . timestamp ( utc_log? ) ,
376
374
[ pid: self ( ) ] ++ metadata ( ) ++ metadata }
377
- notify ( mode , { level , Process . group_leader ( ) , tuple } )
375
+ try do
376
+ notify ( mode , { level , Process . group_leader ( ) , tuple } )
377
+ :ok
378
+ rescue
379
+ ArgumentError -> { :error , :not_available }
380
+ end
381
+ else
382
+ :ok
378
383
end
379
-
380
- :ok
381
384
end
382
385
383
386
@ doc """
@@ -452,10 +455,4 @@ defmodule Logger do
452
455
453
456
defp notify ( :sync , msg ) , do: GenEvent . sync_notify ( Logger , msg )
454
457
defp notify ( :async , msg ) , do: GenEvent . notify ( Logger , msg )
455
-
456
- defp check_logger! do
457
- unless Process . whereis ( Logger ) do
458
- raise "Cannot log messages, the :logger application is not running"
459
- end
460
- end
461
458
end
0 commit comments