Óg v0.2.2 Og

Some convenience utility functions on top of the elixir Logger module. Mostly useful for debugging purposes.

Summary

  • log/1, log/2, alog/1, alog/2, klog/1, klog/2

  • Inspects the data before logging it. For example, this can be helpful for avoiding the Protocol.UndefinedError when logging tuples for example. There are two choices for formatting the data:

    1. Kernel.inspect/2 (from erlang core)
    2. Apex.Format.format/2 from Apex library for pretty printing
  • Configure the inspection function in the config.exs file by passing:

    config :logger, :og, default_inspector: Kernel.inspect/2

    or

    config :logger, :og, default_inspector: Apex.Format.format/2

  • Optionally pass the log_level :debug, :info, :warn or :error which will respect the logger :compile_time_purge_level configuration setting. Defaults to :debug.

  • log_r/1, log_r/2, alog_r/1, alog_r/2, klog_r/1, klog_r/2

  • Performs operations identical to Og.log/4 but returns the data in it’s original form.

  • Can be useful when one wants to log some intermediate data in the middle of a series of data transformations using the |> operator. see the example in log_return/4.

Example configuration

  • Short example:
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,
  default_inspector: &Kernel.inspect/2
  • Long example:
use Mix.Config
limiter1 = "===================    [$level]    ========================"
datetime = "|---$date $time"
metadata = "|---$metadata"
node = "|---$node"
msg = "|---message:"
limiter2 = "==================   [end $level]    ======================="

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: "#{limiter1}\n#{datetime}\n#{metadata}\n#{node}\n#{msg}\n\n$message\n\n#{limiter2}\n",
  metadata: [:module, :function, :line]

config :logger, :og,
  default_inspector: &Kernel.inspect/2,
  kernel: [
    inspect_opts: [width: 70]
  ],
  apex: [
    format_opts: [numbers: :false, color: :false]
  ]

Summary

Functions

Logs the data formatted with the Apex.Format.format/2 function and log_level :debug

Logs the data formatted with the Apex.Format.format/2 function and log_level passed as the second argument

Logs the data formatted with the Apex.Format.format/2 function and log_level :debug

Logs the data formatted with the Apex.Format.format/2 function and log_level passed as the second argument

Logs the data formatted with the Kernel.inspect/2 function and log_level :debug

Logs the data formatted with the Kernel.inspect/2 function and log_level passed as the second argument

Logs the data formatted with the Kernel.inspect/2 function and log_level :debug

Logs the data formatted with the Kernel.inspect/2 function and log_level passed as the second argument

Logs the data formatted with the default_inspector function and log_level :debug

Logs the data formatted with the default_inspector function and log_level passed as the second argument

Logs the data formatted with the default_inspector function and log_level passed as the second argument. Returns the original data

Logs the data formatted with the default_inspector function and log_level :debug. Returns the original data

Functions

alog(data)
alog(any) :: :ok

Logs the data formatted with the Apex.Format.format/2 function and log_level :debug

alog(data, log_level)
alog(any, atom) :: any

Logs the data formatted with the Apex.Format.format/2 function and log_level passed as the second argument

alog_r(data)
alog_r(any) :: any

Logs the data formatted with the Apex.Format.format/2 function and log_level :debug

alog_r(data, log_level)
alog_r(any, atom) :: any

Logs the data formatted with the Apex.Format.format/2 function and log_level passed as the second argument

klog(data)
klog(any) :: :ok

Logs the data formatted with the Kernel.inspect/2 function and log_level :debug

klog(data, log_level)
klog(any, atom) :: any

Logs the data formatted with the Kernel.inspect/2 function and log_level passed as the second argument

klog_r(data)
klog_r(any) :: any

Logs the data formatted with the Kernel.inspect/2 function and log_level :debug

klog_r(data, log_level)
klog_r(any, atom) :: any

Logs the data formatted with the Kernel.inspect/2 function and log_level passed as the second argument

log(data)
log(any) :: :ok

Logs the data formatted with the default_inspector function and log_level :debug

log(data, log_level)
log(any, atom) :: :ok

Logs the data formatted with the default_inspector function and log_level passed as the second argument

log_r(data, log_level)
log_r(any, atom) :: any

Logs the data formatted with the default_inspector function and log_level passed as the second argument. Returns the original data

logr(data)
logr(any) :: any

Logs the data formatted with the default_inspector function and log_level :debug. Returns the original data