dimitarvp

dimitarvp

EDIT: There has been back and forth and I was impatient, operating under the assumption that I am missing something obvious and small. Turns out it wasn’t exactly that. I accepted @LostKobrakai’s comment because it showed me how exactly to configure Logger metadata at runtime, but it was @ibarch’s comment near the end that finally made it work (because apparently Logger ignores “complex” metadata so you have to either do Jason.encode!(metadata) or inspect(metadata).


I have failed the 5-minute test of finding what I need. :grimacing:

So I have this code somewhere in my app:

Logger.error("Invalid payload", payload: message)

I copied my default Logger config to config/dev.exs:

config :logger, :console,
  format: "$time $level $metadata $message\n",
  metadata: [:request_id]

So I call the function with an invalid parameter and all I see is this:

15:54:12.439 error  Invalid payload

No metadata. Tried with info just in case, same result. What should be changed?

Showing Posts 1 to 10

Schultzer

Schultzer

The issue might be that you only including the request_id in the metadata, Logger — Logger v1.20.2 I believe thats why the payload is excluded and was one of the reason that I scraped including capturing logger in https://dbvisor.com that is leveraging telemetry and storing them in a timeseries table in your DB for easy debugging.

dimitarvp

dimitarvp OP

Removed the metadata part of the config, nothing changed sadly.

Also migrated the config to this:

config :logger, :default_handler, level: :all
config :logger, :default_formatter, format: "$time $level $message $metadata\n"

And again, no metadata. :confused:

To respond to the second half of your message, production logging and telemetry is yet to be decided but in the meantime I just want to see the metadata on my machine while testing.

Schultzer

Schultzer

I feel there must be a place that is overriding this. Did you try to print out the config like IO.inspect Application.get_env(:logger)

linusdm

linusdm

Aren’t you missing the :payload value under the metadata config option?

dimitarvp

dimitarvp OP

Didn’t realize metadata was strictly opt-in, OK, included it:

config :logger, :default_handler, level: :all

config :logger, :default_formatter,
  format: "$time $level $message $metadata\n",
  metadata: [:payload]

Still nothing. :confused:

dimitarvp

dimitarvp OP

If anybody wants to play with this before we solve it, here’s a self-contained script that demonstrates my problem (mine is called logging_playground.exs):

Mix.install(
  [],
  config: [
    logger: [
      # console: [format: "$time $level $message $metadata\n"]
      default_handler: [level: :all],
      default_formatter: [format: "$time $level $message $metadata\n", metadata: [:payload]]
    ]
  ]
)

require Logger

Logger.info("Nothing", payload: "metadata")

Then just elixir logging_playground.exs and you should see no metadata, only this:

16:33:09.216 [info] Nothing
linusdm

linusdm

It doesn’t honor the format either (it still adds the square brackets), so it doesn’t pick up on the whole config.

dimitarvp

dimitarvp OP

Yep, now that you mention it, quite interesting actually.

Schultzer

Schultzer

Weird, might be easier to just use telemetry and setup your own handler to print to the console on dev. Then you also gain way more control then Logger could give you.

dimitarvp

dimitarvp OP

Maybe, but I’d be hugely surprised if Elixir doesn’t cover this use case trivially. I must be having a Saturday afternoon moment here and missing something extremely obvious.

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
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
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
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews