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? ![]()
Most Liked
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
If these values are JSON encodable (hint - usually they are not).
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









