Óg v0.0.5 Og

Some convenience utility functions on top of the elixir Logger module.

Note:

The following is the order of precedence for logging:

:error > :warn > :info > :debug

Summary

Functions

Logs contextual information of the environment of the caller and the conn struct

Logs contextual information of the environment of the caller

Logs data after passing data first to the Kernel.inspect/2

Logs data term by using the Kernel.inspect/2 and returns the original data type. Useful in a pipeline of functions

Functions

conn_context(conn, env, log_level \\ :debug, conn_fields \\ [:method, :request_path], inspect_opts \\ [])

Specs

conn_context(conn :: Plug.Conn.t, env :: Macro.Env.t, log_level :: atom, conn_fields :: list, inspect_opts :: list) :: atom

Logs contextual information of the environment of the caller and the conn struct.

Logs by default

"module: #{module}, function: #{function}, line: #{line}, conn_details: { method: #{conn.method}, path: #{conn.request_path}" }"

More conn struct fields can be logged by passing them in the conn_fields list.

Example

defmodule Test do
  use Plug.Test
  def test() do
    conn = Plug.Test.conn(:get, "/test", :nil)
    Og.conn_context(conn, __ENV__)
  end
end

Test.test()

Example

defmodule Test do
  use Plug.Test
  def test() do
    conn = Plug.Test.conn(:get, "/test", :nil)
    Og.conn_context(conn, __ENV__, :warn, [:method, :req_headers, :peer])
  end
end

Test.test()
context(env, log_level \\ :debug, inspect_opts \\ [])

Specs

context(env :: Macro.Env.t, log_level :: atom, inspect_opts :: list) :: atom

Logs contextual information of the environment of the caller.

Logs

module: #{module}, function: #{function}, line: #{line}

Example

defmodule Test do
  def env_test() do
    Og.context(__ENV__)
  end
end

Test.env_test()
log(data, log_level \\ :debug, inspect_opts \\ [])

Specs

log(data :: any, log_level :: atom, inspect_opts :: list) :: atom

Logs data after passing data first to the Kernel.inspect/2.

data : data to be logged

log_level: :info or :debug or :warn or :error

inspect_opts: Keyword list of inspect options. see here

Example

Og.log(String.to_atom("test"))
log_return(data, log_level \\ :debug, inspect_opts \\ [])

Specs

log_return(data :: any, log_level :: atom, inspect_opts :: list) :: any

Logs data term by using the Kernel.inspect/2 and returns the original data type. Useful in a pipeline of functions.

Example

 Og.log_return(String.to_atom("test"))

Example

 %{first: "john", last: "doe"}
 |> Map.to_list()
 |> Enum.filter( &(&1 === {:first, "john"}))
 |> Og.log_return()
 |> List.last()
 |> Tuple.to_list()
 |> List.last()
 |> Og.log_return()
 |> String.upcase()