@@ -30,8 +30,8 @@ defmodule Logger do
3030 The `Logger.info/2` macro emits the provided message at the `:info`
3131 level. Note the arguments given to `info/2` will only be evaluated
3232 if a message is logged. For instance, if the Logger level is
33- set to `:warn `, `:info` messages are never logged and therefore the
34- arguments given above won't even be executed.
33+ set to `:warning `, `:info` messages are never logged and therefore
34+ the arguments given above won't even be executed.
3535
3636 There are additional macros for other levels.
3737
@@ -44,17 +44,22 @@ defmodule Logger do
4444
4545 ## Levels
4646
47- The supported levels, ordered by precedence , are:
47+ The supported levels, ordered by importance , are:
4848
49- * `:debug` - for debug-related messages
50- * `:info` - for information of any kind
51- * `:warn` - for warnings
49+ * `:emergency` - when system is unusable, panics
50+ * `:alert` - for alerts, actions that must be taken immediately,
51+ ex. corrupted database
52+ * `:critical` - for critical conditions
5253 * `:error` - for errors
54+ * `:warning` - for warnings
55+ * `:notice` - for normal, but signifant, messages
56+ * `:info` - for information of any kind
57+ * `:debug` - for debug-related messages
5358
5459 For example, `:info` takes precedence over `:debug`. If your log
55- level is set to `:info`, `:info`, `:warn `, and `:error` will be
56- printed to the console . If your log level is set to `:warn `, only
57- `:warn ` and `:error ` will be printed.
60+ level is set to `:info`, `:info`, `:warning `, and all above it will
61+ be passed to backends . If your log level is set to `:alert `, only
62+ `:alert ` and `:emergency ` will be printed.
5863
5964 ## Metadata
6065
@@ -188,7 +193,12 @@ defmodule Logger do
188193 * `:level` - the logging level. Attempting to log any message
189194 with severity less than the configured level will simply
190195 cause the message to be ignored. Keep in mind that each backend
191- may have its specific level, too.
196+ may have its specific level, too. In addition to levels mentioned
197+ above it also support 2 "meta-levels":
198+
199+ - `:all` - all messages will be logged, conceptualy identical to
200+ `:debug`
201+ - `:none` - no messages will be logged at all
192202
193203 * `:utc_log` - when `true`, uses UTC in logs. By default it uses
194204 local time (i.e., it defaults to `false`).
@@ -214,9 +224,9 @@ defmodule Logger do
214224 Defaults to 500 messages.
215225
216226 * `:discard_threshold_periodic_check` - a periodic check that
217- checks and reports if logger is discarding messages. It logs a warn
227+ checks and reports if logger is discarding messages. It logs a warning
218228 message whenever the system is (or continues) in discard mode and
219- it logs a warn message whenever if the system was discarding messages
229+ it logs a warning message whenever if the system was discarding messages
220230 but stopped doing so after the previous check. By default it runs
221231 every `30_000` milliseconds.
222232
@@ -229,7 +239,7 @@ defmodule Logger do
229239 `config/config.exs` file:
230240
231241 config :logger,
232- level: :warn ,
242+ level: :warning ,
233243 truncate: 4096
234244
235245 ### Erlang/OTP integration
@@ -341,11 +351,11 @@ defmodule Logger do
341351
342352 * `:debug` - color for debug messages. Defaults to: `:cyan`
343353
344- * `:info` - color for info messages. Defaults to: `:normal`
354+ * `:info` - color for info and notice messages. Defaults to: `:normal`
345355
346- * `:warn` - color for warn messages. Defaults to: `:yellow`
356+ * `:warn` - color for warning messages. Defaults to: `:yellow`
347357
348- * `:error` - color for error messages. Defaults to: `:red`
358+ * `:error` - color for error and higher messages. Defaults to: `:red`
349359
350360 See the `IO.ANSI` module for a list of colors and attributes.
351361
@@ -403,7 +413,7 @@ defmodule Logger do
403413 You can read more about formatting in `Logger.Formatter`, especially
404414 if you want to support custom formatting in a custom backend.
405415
406- ### Custom backends
416+ ### Elixir custom backends
407417
408418 Any developer can create their own `Logger` backend. Since `Logger`
409419 is an event manager powered by `:gen_event`, writing a new backend
@@ -428,7 +438,9 @@ defmodule Logger do
428438
429439 * `{level, group_leader, {Logger, message, timestamp, metadata}}` where:
430440 * `level` is one of `:debug`, `:info`, `:warn`, or `:error`, as previously
431- described
441+ described (for compatibility with pre 1.10 backends the `:notice` will
442+ be translated to `:info` and all messages above `:error` will be translated
443+ to `:error`)
432444 * `group_leader` is the group leader of the process which logged the message
433445 * `{Logger, message, timestamp, metadata}` is a tuple containing information
434446 about the logged message:
@@ -508,8 +520,9 @@ defmodule Logger do
508520
509521 Erlang/OTP handlers must be listed under your own application:
510522
511- config :my_app, :logger,
512- [:handler, :name_of_the_handler, ACustomHandler, configuration = %{}]
523+ config :my_app, :logger, [
524+ {:handler, :name_of_the_handler, ACustomHandler, configuration = %{}}
525+ ]
513526
514527 And then explicitly attached in your `c:Application.start/2` callback:
515528
@@ -525,11 +538,12 @@ defmodule Logger do
525538 been started, which means the configuration above would have no effect.
526539 """
527540
528- @ type level :: :error | :warn | :info | :debug
541+ @ type level ::
542+ :emergency | :alert | :critical | :error | :warning | :warn | :notice | :info | :debug
529543 @ type backend :: :gen_event . handler ( )
530544 @ type message :: IO . chardata ( ) | String.Chars . t ( )
531545 @ type metadata :: keyword ( )
532- @ levels [ :error , :warn , :info , :debug ]
546+ @ levels [ :emergency , :alert , :critical , : error, :warning , :notice , :info , :debug ]
533547
534548 @ metadata :logger_enabled
535549 @ compile { :inline , enabled?: 1 }
@@ -622,7 +636,8 @@ defmodule Logger do
622636 @ spec level ( ) :: level ( )
623637 def level ( ) do
624638 % { level: level } = :logger . get_primary_config ( )
625- Logger.Handler . erlang_level_to_elixir_level ( level )
639+
640+ level
626641 end
627642
628643 @ doc """
@@ -828,7 +843,7 @@ defmodule Logger do
828843 :logger . macro_log ( % { } , level , chardata , add_elixir_domain ( metadata ) )
829844 end
830845
831- # # TODO: Remove that in Elixir 2.0
846+ # TODO: Remove that in Elixir 2.0
832847 def __do_log__ ( level , other , metadata ) do
833848 IO . warn ( "passing #{ inspect ( other ) } to Logger is deprecated, expected a binary or an iolist" )
834849 :logger . macro_log ( % { } , level , to_string ( other ) , add_elixir_domain ( metadata ) )
@@ -840,69 +855,65 @@ defmodule Logger do
840855
841856 defp add_elixir_domain ( metadata ) , do: Map . put ( metadata , :domain , [ :elixir ] )
842857
843- @ doc """
844- Logs a warning message.
845-
846- Returns `:ok`.
847-
848- ## Examples
849-
850- Logger.warn("knob turned too far to the right")
851-
852- """
853- # TODO: Deprecate it in favour of `warning/1-2` macro
854- defmacro warn ( chardata_or_fun , metadata \\ [ ] ) do
855- maybe_log ( :warn , chardata_or_fun , metadata , __CALLER__ )
856- end
858+ messages = [
859+ # Airplane 2
860+ "We are also out of coffee" ,
861+ # Red Alert 2
862+ "Kirov reporting" ,
863+ # Spies like us
864+ "Doctor? Doctor" ,
865+ # 2001: Space Odyssey
866+ "I'm sory Dave" ,
867+ # Lost in Space
868+ "Danger, Will Robinson" ,
869+ # The Graduate
870+ "Mrs. Robinson, you are trying to seduce me" ,
871+ # Dr. No
872+ "Bond. James Bond." ,
873+ # A Bug's Life
874+ "I'm the only stick with eyeballs"
875+ ]
857876
858- @ doc """
859- Logs an info message.
877+ for { level , message } <- Enum . zip ( @ levels , messages ) do
878+ @ doc """
879+ Logs a #{ level } message.
860880
861- Returns `:ok`.
881+ Returns `:ok`.
862882
863- ## Examples
883+ ## Examples
864884
865- Logger.info("mission accomplished ")
885+ Logger.#{ level } (" #{ message } ")
866886
867- """
868- defmacro info ( chardata_or_fun , metadata \\ [ ] ) do
869- maybe_log ( :info , chardata_or_fun , metadata , __CALLER__ )
887+ """
888+ defmacro unquote ( level ) ( chardata_or_fun , metadata \\ [ ] ) do
889+ maybe_log ( unquote ( level ) , chardata_or_fun , metadata , __CALLER__ )
890+ end
870891 end
871892
872893 @ doc """
873- Logs an error message.
894+ Logs a warning message.
874895
875896 Returns `:ok`.
876897
877- ## Examples
878-
879- Logger.error("oops")
880-
881- """
882- defmacro error ( chardata_or_fun , metadata \\ [ ] ) do
883- maybe_log ( :error , chardata_or_fun , metadata , __CALLER__ )
884- end
885-
886- @ doc """
887- Logs a debug message.
888-
889- Returns `:ok`.
898+ This macro is deprecated in favour of `warning/2`.
890899
891900 ## Examples
892901
893- Logger.debug("hello? ")
902+ Logger.warn("knob turned too far to the right ")
894903
895904 """
896- defmacro debug ( chardata_or_fun , metadata \\ [ ] ) do
897- maybe_log ( :debug , chardata_or_fun , metadata , __CALLER__ )
905+ # TODO: Hard deprecate it in favour of `warning/1-2` macro
906+ defmacro warn ( chardata_or_fun , metadata \\ [ ] ) do
907+ maybe_log ( :warning , chardata_or_fun , metadata , __CALLER__ )
898908 end
899909
900910 @ doc """
901911 Logs a message with the given `level`.
902912
903913 Returns `:ok`.
904914
905- The macros `debug/2`, `warn/2`, `info/2`, and `error/2` are
915+ The macros `debug/2`, `info/2`, `notice/2`, `warning/2`,
916+ `error/2`, `critical/2`, `alert/2`, and `emergency/2` are
906917 preferred over this macro as they can automatically eliminate
907918 the call to `Logger` altogether at compile time if desired
908919 (see the documentation for the `Logger` module).
0 commit comments