Óg v1.1.2 Og
Óg is a small collection of debugging helper functions. Og is a debugging tool primarily
intendend for development, the use of ordinary Logger is preferred for production.
Summary
log/2- logs the data transformed by the inspector function and returns:oklog_r/2- logs the data transformed by the inspector function and returns the original data.Inspection of the data before logging it can be helpful in a debugging context for example for
- Avoiding the 
Protocol.UndefinedErrorwhen logging tuples. - Not needing to require Logger
 
- Avoiding the 
 Formatting with
Kernel.inspecton the data carries an overhead soOg.log/2andOg.log_r/2should be probably be reserved for debugging code in:devenvironments.
Configuration
config :logger, :og,
  kernel_opts: [width: 70],
  apex_opts: [numbers: :false, color: :false],
  sanitize_by_default: :false,
  default_inspector: :kernel
Configuration options
kernel_opts- corresponds to elixir inspect opts forIO.inspect/2andKernel.inspect/2, refer tohttps://hexdocs.pm/elixir/Inspect.Opts.htmlapex_opts- corresponds to options for theApex.Format.format/2function, refer tohttps://github.com/BjRo/apex/blob/master/lib/apex/format.exsanitize_by_default- defaults to:false, when set to:true, an attempt will be made to apply theSecureLogFormatter.sanitize/1function on the data before applying the inspection function. For this function to take any effect, the settings forSecureLogFormattermust also be placed inconfig.exs. See secure_log_formatter for more details.default_inspector- corresponds to the default inspector which will apply to the data passed to the log function. This can be overriden in the options of the log function. The options are:kernelor:apex, the default is:kernel.
Example configuration for secure_log_formatter, as referenced at the following secure_log_formatter url.
config :logger,
secure_log_formatter:
  [
    # Map and Keyword List keys who's value should be hidden
    fields: ["password", "credit_card", ~r/.*_token/],
    # Patterns which if found, should be hidden
    patterns: [~r/4[0-9]{15}/] # Simple credit card example
    # defaults to "[REDACTED]"
    replacement: "[PRIVATE]"
  ]
        Summary
Functions
Formats the data using an inspector function, logs it and returns the
atom :ok
Formats the data using an inspector function, logs it and returns the original data
Functions
log(any, Keyword.t) :: :ok
log(data :: any, env :: Macro.Env.t) :: :ok
log(data :: any, level :: atom) :: :ok
Formats the data using an inspector function, logs it and returns the
atom :ok.
Notes:
There is an overhead in converting the data to
other formats such as a binary representation. Hence,
Og.log/2 and Og.log_r/2 are preferred for
development debugging purposes only.
opts
level: defaults to
:debug.env: defaults to
:nil.inspector: defaults to
:default_inspectorin the application config.exs and if not set falls back toKernel.inspect/2. The inspector function determines what function transforms the data prior to logging. Currently the options are:kernelor:apexwhich use the functions&Kernel.inspect/2and&Apex.Format.format/2respectively.sanitize: defaults to
:sanitize_by_defaultin the application config.exs and if not set falls back to:false. When set to:truethe functionSecureLogFormatter.sanitize/1will be applied to the data prior to logging the data. See secure_log_formatter for more details.
Examples:
Og.log(%{test: "test"})
Og.log(%{test: "test"}, level: :info)
Og.log(%{test: "test"}, env: __ENV__)
Og.log(%{test: "test"}, inspector: :apex)
Og.log(%{credit_card: "4111111111111111"}, sanitize: :true)
  log(data :: any, env :: Macro.Env.t, level :: atom) :: :ok
log(data :: any, level :: atom, env :: Macro.Env.t) :: :ok
log_r(any, Keyword.t) :: any
log_r(data :: any, env :: Macro.Env.t) :: any
log_r(data :: any, level :: atom) :: any
Formats the data using an inspector function, logs it and returns the original data.
Notes:
There is an overhead in converting the data to
other formats such as a binary representation. Hence,
Og.log/2 and Og.log_r/2 are preferred for
development debugging purposes only.
opts
level: defaults to
:debug.env: defaults to
:nil.inspector: defaults to
:default_inspectorin the application config.exs. The inspector function determines what function transforms the data prior to logging. Currently the options are:kernelor:apexwhich use the functions&Kernel.inspect/2and&Apex.Format.format/2respectively.sanitize: defaults to
:sanitize_by_defaultin the application config.exs. When set to:truethe functionSecureLogFormatter.sanitize/1will be applied to the data prior to logging the data. See secure_log_formatter for more details.
Examples:
Og.log(%{test: "test"})
Og.log(%{test: "test"}, level: :info)
Og.log(%{test: "test"}, env: __ENV__)
Og.log(%{test: "test"}, inspector: :apex)
Og.log(%{credit_card: "4111111111111111"}, sanitize: :true)
  log_r(data :: any, env :: Macro.Env.t, level :: atom) :: any
log_r(data :: any, level :: atom, env :: Macro.Env.t) :: any