Packages

ExClaw — OpenClaw rebuilt on ADK Elixir

Current section

Files

Jump to
ex_claw lib ex_claw plugin logger_plugin.ex
Raw

lib/ex_claw/plugin/logger_plugin.ex

defmodule ExClaw.Plugin.LoggerPlugin do
@moduledoc """
Example plugin that logs all events with timestamps.
"""
@behaviour ExClaw.Plugin
require Logger
@impl true
def init(config) do
level =
case Map.get(config, "level", "info") do
"debug" -> :debug
"info" -> :info
"warning" -> :warning
"error" -> :error
_ -> :info
end
{:ok, %{level: level}}
end
@impl true
def handle_event(event, payload, %{level: level} = state) do
Logger.log(
level,
"[ExClaw.Plugin] #{event} at #{DateTime.utc_now()}: #{inspect(Map.keys(payload))}"
)
{:ok, state}
end
end