gmile
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? ![]()
Trending in Questions
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
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
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
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
krasenyp
Your format function looks incorrect. It should take only two arguments - the log event and the formatter configuration, as per docs.
gmile
That doesn’t seem to help
I just tried a simple thing to rule out possibility that I am misconfiguring the logger: removal of handler. It doesn’t work either:
So now I there are two possibilities left:
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 aformatter_config()which happens to be map as well. Your function then should returnunicode:chardata(). In your case you break that contract and instead you return list that is mix between chartists, maps, and integers.ken-kost
Would
Jason.encode!help?hauleth
If these values are JSON encodable (hint - usually they are not).
gmile
@hauleth thanks! I’ve modified the code according to your comment about the contract,
but the original issue is still there - this code prints “typical” output, and not the
“This log entry is redacted completely”.
Can you spot an issue with this code?
I wonder if I have the wrong expectations regarding how the formatter for
:ssl_handlermust be updated, for the update to take effect
krasenyp
I spent some time to look into your issue and found out that if I set
filter_defaultofssl_handlertotrueviathe custom formatter is called.
Edit: On a second thought, it’s natural for your formatter to not be called because the log event is filtered out by
ssl’sfilter_non_sslfilter. Combined withfilter_default: :stop, the log event is not getting to the handler at all.gmile
Thanks for looking into this @krasenyp! But unfortunately, even adding that line doesn’t exactly work as expected - e.g. will not replace the “warning”. If I add a line that you mentioned, I see this output:
The expectation is that “Description: …” and “Reason: …” lines are gone completely