Koszal

Koszal

Configuring the default logger through a config file

The bash script below generates and umbrela project (mix new --umbrella logcfg) and then an app (mix new demo). It then creates a task and adjusts config for the :default logger. Finally, everything is compiled and the generated task runs. (mix hello). Despite setting :type and :filesync_repeat_interval in the config, the logger still sees the default values:

19:07:52.772 [warning] config.type :standard_io
19:07:52.773 [warning] config.type :no_repeat

Why?
Elixir 1.15.7 (compiled with Erlang/OTP 26)

Koszal

#!/bin/bash

mkdir /tmp/logger-$$
cd    /tmp/logger-$$

mix new --umbrella logcfg
cd logcfg

dsn=`pwd`

cd $dsn/apps
mix new demo

mkdir -p $dsn/apps/demo/lib/mix

cat <<TASK > $dsn/apps/demo/lib/mix/hello.ex
defmodule Mix.Tasks.Hello do
  use Mix.Task
  require Logger

  def run(_) do
    :logger.get_handler_config(:default) |> IO.inspect()

    {:ok, lcfg} = :logger.get_handler_config(:default)
    Logger.warning( "config.type #{ inspect(lcfg[:config][:type]) }" )
    Logger.warning( "config.filesync_repeat_interval #{ inspect(lcfg[:config][:filesync_repeat_interval]) }" )
  end
end
TASK

cat <<CONFIG >> $dsn/config/config.exs
config :logger, :default,
  config: [
    type: :standard_error,
    filesync_repeat_interval: 5000
  ]
CONFIG

cd $dsn
mix compile
mix hello
pwd

Most Liked

cmo

cmo

why do you have this there if you’re trying to log to a file? Have you tried removing that or using :file as per the docs?

hauleth

hauleth

Answer adequate to your post:

I have tested, without :type field it worked perfectly.

hauleth

hauleth

If you are using OTP 24+ and you aware of the consequences, then you can run logger:reconfigure/0 as part of your startup script. In general default handler is only partially configurable after it started.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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

We're in Beta

About us Mission Statement