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

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
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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
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
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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
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
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New

Other popular topics Top

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
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement