xsteve

xsteve

I have a deployed Phoenix LiveView App.
When I start it with a shell, I see output like this:

10:43:25.306 request_id=F_xtup9AcaphOX8AAEvB [info] GET /some-page/
10:43:25.312 request_id=F_xtup9AcaphOX8AAEvB [info] Sent 200 in 6ms
10:46:14.756 [info] CONNECTED TO Phoenix.LiveView.Socket in 42µs
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Parameters: %{“_csrf_token” => “…”, “_live_referer” => “undefined”, “_mounts” => “0”, “_track_static” => %{“0” => “webpage.com”, “1” => “webpage.com”}, “vsn” => “2.0.0”}

How to configure (turn off) this messages?
Is there a drawback when I turn these off? Do I miss some important stuff?
Can the debug levels be tweaked in the shell at runtime?

Showing Posts 1 to 7

slouchpie

slouchpie

I am not at my computer but read this: Phoenix.Logger — Phoenix v1.8.8

Search that page for the word “level”

xsteve

xsteve OP

I changed endpoint.ex like this:
socket “/live”, Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options], log: false],
longpoll: [connect_info: [session: @session_options], log: false]

The CONNECTED TO Phoenix.LiveView.Socket message is gone.

However the request_id lines are still present. How to find out where they are coming from and how to disable them?

slouchpie

slouchpie

I strongly suggest using log: :warning instead of log: false.

You will want to see warning/error/alert/critical/emergency level logs. Hopefully they never happen but you will definitely want to see when they do.

I am not sure where the other logs come from. If I get some free time this week, I will dig into it.

Update: I was wrong about log: :warning. This actually changes the level of the logs printed! That is, logs which are normally :info are now :warning.

slouchpie

slouchpie

To get rid of the logs with the request_id metadata in them, do something like this

  plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint], log: false

That lives in endpoint.ex. You should already have this plug in there.

slouchpie

slouchpie

You can have more control over which routes get logged by using an MFA (module-function-arity) tuple.

plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint], log: {__MODULE__, :log_level, []}

@quiet_paths ["health", "healthz", "healthcheck", "favicon.ico"]
def log_level(%{path_info: [head | _]}) when head in @quiet_paths, do: false
def log_level(_), do: :info 

This would do the usual logging except for paths /health, /healthz, etc.

xsteve

xsteve OP

Thanks. That looks nice.
What is a good way to make the log_level runtime configurable?
I’d like to switch e.g. from :info to false. Therefore I need some state for the log_level function.

xsteve

xsteve OP

Exactly - I experimented with the :info, :warning settings.
I changed it to :debug. That way they should not be longer printed in the deployed version.

Here is some info about logging in elixir:
https://staknine.com/logging-in-elixir-with-logger/

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews