ExSeq
ExSeq is an Elixir Logger backend for sending logs to Seq using the Compact Log Event Format (CLEF).
Features
- Minimal configuration required
- Converts Elixir log messages and metadata into CLEF events
- Sends events asynchronously through a GenServer
- Filters log messages based on minimum log level
Installation
Add ex_seq to your list of dependencies in mix.exs:
def deps do
[
{:ex_seq, "~> 0.1.0"}
]
endThen run:
mix deps.getConfiguration
In your config.exs, set up the logger to use ExSeq:
config :logger,
backends: [:console, ExSeq],
level: :info
config :logger, ExSeq,
level: :info,
seq_url: "http://localhost:5341/ingest/clef",
api_key: "YOUR_SEQ_API_KEY",levelsets the minimum level for sending to Seq. Levels below this are ignored.seq_urlis the endpoint of your Seq server.api_keyis your Seq API key if required for authentication (optional if Seq isn’t secured).
You can also tune the flush interval and batch size:
flush_interval: 5, # Flush every 5 seconds
batch_size: 100How It Works
ExSeqimplements the:gen_eventbehavior, which the ElixirLoggeruses for backends.-
When a log event arrives,
ExSeqchecks if its level is >= the configured minimum. If so, it converts the event to a CLEFEvent struct. -
The event is then sent asynchronously to the
ExSeq.FlusherGenServer for batching and sending to Seq.
Usage
After adding ExSeq to your logger backends and setting your :level, just log as usual in Elixir:
Logger.debug("This is a debug log") # Will be filtered out if :level >= :info
Logger.info("An info-level message")
Logger.warn("A warning")
Logger.error("An error occurred!")
Each message you log is converted into a CLEF event and sent to Seq. If you’ve configured your seq_url and (optionally) an api_key correctly, you should see your events in the Seq UI under the configured ingestion endpoint.
Example
defmodule MyApp do
require Logger
def run do
Logger.info("Starting application", foo: "bar")
# ...
Logger.error("Oops, something went wrong!", user_id: 123)
end
end
You can then start your application (e.g. via iex -S mix) and see the logs in Seq if everything is configured properly.
Notes
ExSequses a custom minimal:gen_server(theFlusher) to batch events and send them in the background.- Timestamps are pulled from the Elixir logger metadata if present, or from the default Erlang timestamp.
-
The log level is converted from Elixir’s levels (
:debug,:info,:warn,:error) to CLEF’s equivalent (Debug,Information,Warning,Error) viaCLEFLevel.elixir_to_clef_level/1.
Contributing
- Fork the repository.
- Create a feature branch.
- Make your changes and write tests if necessary.
- Submit a Pull Request.
License
This project is MIT Licensed.