Vik.Logger (Vik v0.0.1-rc1)

View Source

Simple logging server.

The server holds a list of all log entries in memory; this comprises all exceptions and related messages emitted since application boot.

This server pushes messages to the default webhook configured via the DEFAULT_WEBHOOK environment variable. An additional logger-specific webhook is supported to.

To utilize this functionality, export the LOGGER_WEBHOOK variable in your system's environment:

export LOGGER_WEBHOOK="https://discord.com/api/webhooks/..."

The webhook will also receive messages in the following JSON structured format (as defined by Vik.Webhook.payload/0):

{"event": "logger.message", "content": "** (RuntimeError) hewwo world :3"}

Summary

Functions

Returns a specification to start this module under a supervisor.

Delete n oldest log entries.

Logs an exception.

Logs a simple message.

Starts the server.

Subscribes to log entries via PubSub.

Returns n latest log entries.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(n \\ :all)

@spec clear(pos_integer() | :all) :: :ok

Delete n oldest log entries.

exception(e, stacktrace \\ [])

@spec exception(Exception.t(), Exception.stacktrace()) :: :ok

Logs an exception.

Excludes all stacktraces unrelated to user code. (Everything outside the Vik.UserShard namespace.)

info(message)

@spec info(String.t()) :: :ok

Logs a simple message.

start_link(opts)

@spec start_link([]) :: :ok

Starts the server.

subscribe()

@spec subscribe() :: :ok

Subscribes to log entries via PubSub.

Examples

@initial_lines 50

def mount(_, _, socket) do
  Vik.Logger.subscribe()

  lines = Vik.Logger.tail(@initial_lines)
  {:ok, stream(socket, :logs, lines)}
end

def handle_info({:lines, lines}, socket) do
  {:noreply, stream(socket, :logs, lines, at: 0)}
end

tail(n)

@spec tail(pos_integer()) :: [String.t()]

Returns n latest log entries.