Óg v1.0.1 Og
Óg is a small collection of debugging helper functions. Og is a debugging tool for development,
the use of ordinary Logger
is preferred for production.
Summary
log/2
- logs the data transformed by the inspector function and returns:ok
log_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
- Avoiding the
Protocol.UndefinedError
when logging tuples for example. - Not needing to require Logger
- Avoiding the
However, the functions
Og.log/2
andOg.log_r/2
should be reserved for debugging code only in:dev
environments and should not be used in production because:- Formatting the data carries an overhead.
Example configuration of the Logger
use Mix.Config
config :logger,
backends: [:console],
level: :debug,
compile_time_purge_level: :debug,
compile_time_application: :my_app,
truncate: (4096 * 8),
utc_log: :false
config :logger, :console,
level: :debug,
format: "$time $metadata [$level] $message\n",
metadata: []
config :logger, :og,
kernel_opts: [width: 70],
apex_opts: [numbers: :false, color: :false]
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_inspector
in the application config.exs and if
not set, otherwise, defaults to :kernel
. The inspector function determines how the
data will be transformed. Currently the options are :kernel
or :apex
which use
the functions &Kernel.inspect/2
and &Apex.Format.format/2
respectively.
Examples:
Og.log(%{test: "test"})
Og.log(%{test: "test"}, level: :info)
Og.log(%{test: "test"}, env: __ENV__)
Og.log(%{test: "test"}, inspector: :apex)
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_inspector
in the application config.exs and if
not set, otherwise, defaults to :kernel
. The inspector function determines how the
data will be transformed. Currently the options are :kernel
or :apex
which use
the functions &Kernel.inspect/2
and &Apex.Format.format/2
respectively.
Examples:
Og.log(%{test: "test"})
Og.log(%{test: "test"}, level: :info)
Og.log(%{test: "test"}, env: __ENV__)
Og.log(%{test: "test"}, inspector: :apex)
log_r(data :: any, env :: Macro.Env.t, level :: atom) :: any
log_r(data :: any, level :: atom, env :: Macro.Env.t) :: any