vkryukov

vkryukov

LoggerBackends - SQL Logger backends functionality for Elixir v1.15+

Hi, I’ve created an SQL logger backend using LoggerBackends: GitHub - vkryukov/logger_backends_sql.

It safely stores all metadata and can be configured to use an existing Repo and/or Schema.

The simplest setup uses an SQLite3 database for logs:

# config/config.exs
config :logger, LoggerBackends.SQL,
  level: :debug,
  path: "./logs.sqlite"

Logs will be written to the logs table. You can also use an existing repo and customize the table name:

# config/config.exs
config :logger, LoggerBackends.SQL,
   repo: MyApp.Repo,
   table_name: "log_messages"

You can use your own Schema for log messages - just ensure the schema module defines a changeset/1 function that accepts time, message, and meta arguments.

Feedback welcome!

First Post!

vkryukov

vkryukov

While we are here, I would like people’s thoughts on the best way to configure the backend during the runtime.

LoggerBackends offers configure/2, which can be called like this:

LoggerBackends.configure(LoggerBackends.SQL,
   option1: value1,
   option2: value2,
   ...
)

and will send a :configure event to the backend that it can capture. The reference implementation for LoggerBackend.Console is here. This call will only succeed after a backend has already been added with LoggerBackend.add(LoggerBackends.SQL) (as someone needs to listen to these events).

However, you definitely want to set the path to a SQLite log database before adding the backend to perform all the initialization in the backend’s init function.

Something like this would be nice

LoggerBackends.add(LoggerBackends.SQL,
   path: "./my.sqlite", 
   repo: nil
)

However, LoggerBackends.add/2 only processes the :flush option and ignores everything else.

So my current solution is to expose my own configure/1 to do the runtime config:

LoggerBackends.SQL.configure(
  path: "./test1.sqlite",
  repo: nil
)
LoggerBackends.add(LoggerBackends.SQL)

The previous option with LoggerBackend.add/2 is IMHO cleaner, but requires changing the existing contract.

Thoughts?

Where Next?

Popular in Libraries Top

kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
sabiwara
Dune is a sandbox for Elixir and aims to safely evaluate user-provided code. You can try it out using this basic Elixir playground made ...
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 13487 106
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Sub Categories:

We're in Beta

About us Mission Statement