View Source File.Only.Logger.Proxy (File-Only Logger v0.2.31)

Implements logging messages to files only (not to the console).

Summary

Types

Message to be logged

Functions

Returns the application for the current process or for the given module.

Returns a formatted heredoc to trace a message from the given env (Macro.Env).

Returns a formatted heredoc to trace a message from the given env (Macro.Env) and module.

Returns string "<module>.<function>/<arity>" e.g. "My.Math.sqrt/1" from the given env (Macro.Env).

Returns true if value is a positive integer, otherwise false.

Returns the current library name.

Writes message to the configured log file of logging level level.

Will prefix string with "\n<padding>" if string is longer than <line_length> - offset where <padding> and <line_length> are respectively the :padding and :line_length options.

Returns the given module as a string.

Types

message()

@type message() :: String.t() | iodata() | fun() | keyword() | map()

Message to be logged

Functions

app(module)

@spec app(module()) :: atom()

Returns the application for the current process or for the given module.

Returns :undefined if the current process does not belong to any application or the given module is not listed in any application spec.

Examples

iex> alias File.Only.Logger.Proxy
iex> Proxy.app(__MODULE__)
:undefined

iex> alias File.Only.Logger.Proxy
iex> Proxy.app(Proxy)
:file_only_logger

from(env)

@spec from(Macro.Env.t()) :: String.t()

Returns a formatted heredoc to trace a message from the given env (Macro.Env).

Examples

iex> alias File.Only.Logger.Proxy
iex> heredoc = """
...> • App: undefined
...> • Library: file_only_logger
...> • Function:\s
...>   File.Only.Logger.ProxyTest.'doctest\
...> """
iex> Proxy.from(__ENV__) =~ heredoc
true

from(env, module)

@spec from(Macro.Env.t(), module()) :: String.t()

Returns a formatted heredoc to trace a message from the given env (Macro.Env) and module.

Examples

iex> alias File.Only.Logger.Proxy
iex> heredoc = """
...> • App: undefined
...> • Library: file_only_logger
...> • Module: File.Only.Logger.ProxyTest
...> • Function:\s
...>   File.Only.Logger.ProxyTest.'doctest\
...> """
iex> Proxy.from(__ENV__, __MODULE__) =~ heredoc
true

fun(env)

@spec fun(Macro.Env.t()) :: String.t()

Returns string "<module>.<function>/<arity>" e.g. "My.Math.sqrt/1" from the given env (Macro.Env).

Examples

iex> defmodule My.Math do
iex>   alias File.Only.Logger.Proxy
iex>   def sqrt(_number) do
iex>     Proxy.fun(__ENV__)
iex>   end
iex> end
iex> My.Math.sqrt(9)
"File.Only.Logger.ProxyTest.My.Math.sqrt/1"

is_pos_integer(value)

(macro)

Returns true if value is a positive integer, otherwise false.

lib()

@spec lib() :: atom()

Returns the current library name.

Examples

iex> alias File.Only.Logger.Proxy
iex> Proxy.lib()
:file_only_logger

log(level, message)

@spec log(Logger.level(), message()) :: :ok

Writes message to the configured log file of logging level level.

Examples

iex> alias File.Only.Logger.Proxy
iex> Proxy.log(:debug, "*** String message ***")
:ok

iex> alias File.Only.Logger.Proxy
iex> Proxy.log(:debug, ~c"*** charlist message ***")
:ok

iex> alias File.Only.Logger.Proxy
iex> Proxy.log(:debug, [~c"*** Improper ", ~c"List " | "Message ***"])
:ok

iex> alias File.Only.Logger.Proxy
iex> Proxy.log(:debug, fn -> "*** Function message ***" end)
:ok

iex> alias File.Only.Logger.Proxy
iex> Proxy.log(:debug, %{"first" => {1, 2, 3}, "last" => [1, 2, 3]})
:ok

iex> alias File.Only.Logger.Proxy
iex> Proxy.log(:debug, first: {?a, ?b, ?c}, last: [0, 1, 2])
:ok

maybe_break(string, offset, options \\ [])

@spec maybe_break(String.t(), pos_integer(), keyword()) :: String.t()

Will prefix string with "\n<padding>" if string is longer than <line_length> - offset where <padding> and <line_length> are respectively the :padding and :line_length options.

Options

  • :line_length (positive integer) - the preferred line length of messages sent to the log files. Defaults to 80.
  • :padding (string) - Filler inserted after the line break. Defaults to "\s\s".

Examples

iex> alias File.Only.Logger.Proxy
iex> supercal = "supercalifragilisticexpialidocious"
iex> """
...> • Feeling: #{inspect(supercal) |> Proxy.maybe_break(11)}
...> """
"""
• Feeling: "supercalifragilisticexpialidocious"
"""

iex> alias File.Only.Logger.Proxy
iex> supercal = "supercalifragilisticexpialidocious"
iex> supercal! = "#{supercal}ly #{supercal}!"
iex> """
...> • Feeling: #{String.capitalize(supercal!) |> Proxy.maybe_break(11)}
...> """
"""
• Feeling:\s
  Supercalifragilisticexpialidociously supercalifragilisticexpialidocious!
"""

iex> import File.Only.Logger.Proxy, only: [maybe_break: 3]
iex> supercal = :supercalifragilisticexpialidocious
iex> msg = "Today I'm feeling astonishingly #{supercal}..."
iex> """
...> -- Message: #{inspect(msg) |> maybe_break(12, padding: "\s\s\s")}
...> """
"""
-- Message:\s
   "Today I'm feeling astonishingly supercalifragilisticexpialidocious..."
"""

mod(module)

@spec mod(module()) :: String.t()

Returns the given module as a string.

Examples

iex> alias File.Only.Logger.Proxy
iex> Proxy.mod(__MODULE__)
"File.Only.Logger.ProxyTest"

iex> alias File.Only.Logger.Proxy
iex> Proxy.mod(Elixir.Date.Range)
"Date.Range"