gmile

gmile

Custom formatter for logs coming from :ssl application. How?

I’m failing to use my own custom module to format log entries coming from :ssl application, under OTP 25. Here’s my code:

require Logger

defmodule MyFormatter do
  def format(level, message, _timestamp, _metadata) do
    ['[', level, ']', 'Simon says:', message, ?\n]
  end
end

:inets.start()
:ssl.start()

:ok = :logger.update_handler_config(:ssl_handler, :formatter, {MyFormatter, %{}})

:httpc.request('https://github.com')

The output still prints what looks like a default message:

11:50:31.761 [warning] Description: ~c"Server authenticity is not verified since certificate path validation is not enabled"
     Reason: ~c"The option {verify, verify_peer} and one of the options 'cacertfile' or 'cacerts' are required to enable this."

If I check handler configuration via :logger.get_handler_config(:ssl_handler) it looks as expected:

{:ok,
 %{
   config: %{
     burst_limit_enable: true,
     burst_limit_max_count: 500,
     burst_limit_window_time: 1000,
     drop_mode_qlen: 200,
     filesync_repeat_interval: :no_repeat,
     flush_qlen: 1000,
     overload_kill_enable: false,
     overload_kill_mem_size: 3000000,
     overload_kill_qlen: 20000,
     overload_kill_restart_after: 5000,
     sync_mode_qlen: 10,
     type: :standard_io
   },
   filter_default: :stop,
   filters: [
     filter_non_ssl: {&:logger_filters.domain/2, {:log, :sub, [:otp, :ssl]}}
   ],
   formatter: {MyFormatter, %{}},
   id: :ssl_handler,
   level: :debug,
   module: :logger_std_h
 }}

What I might be doing wrong? :thinking:

Most Liked

hauleth

hauleth

Yes, the values that are passed to the formatter aren’t strings. That is your problem. Check out documentation

It says that 1st argument is log_event() which is a map, and 2nd argument is a formatter_config() which happens to be map as well. Your function then should return unicode:chardata(). In your case you break that contract and instead you return list that is mix between chartists, maps, and integers.

hauleth

hauleth

If these values are JSON encodable (hint - usually they are not).

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
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
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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

Other popular topics Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement