james

james

Logger format

Sorry if this has been asked before.

Is it possible to do something like:
config :logger, :console, format: “[$date][$time][$node][$level][$file][$function][$line] $message\n”

where the logger automatically puts in the function, line and file name?

for example, in C/C++ you can use the macros __ FILE __ and __ LINE __.

I mostly want to be lazy and cut and paste my:

Logger.warn “no pattern matched”

with adding the specifics.

Marked As Solved

wfgilman

wfgilman

The file, function and line are included in in the metadata, not the format. These are the acceptable format options:

Formatting

The valid parameters you can use are:

$time - time the log message was sent
$date - date the log message was sent
$message - the log message
$level - the log level
$node - the node that prints the message
$metadata - user controlled data presented in “key=val key2=val2” format
$levelpad - sets to a single space if level is 4 characters long, otherwise set to the empty space. Used to align the message after level.

Metadata

In addition to the keys provided by the user via Logger.metadata/1, the following extra keys are available to the :metadata list:

:application - the current application
:module - the current module
:function - the current function
:file - the current file
:line - the current line
:pid - the current process ID

Try this:

config :logger, :console, format: "[$date][$time][$node][$level] $metadata$message\n"
  metadata: [:file, :function, :line]

See here: Example of using Logger.metadata - #2 by smpallen99

Also Liked

james

james

Thanks wfgilman,

that worked great.

I just had a drop in a comma after the:
$metadata$message\n",

Last Post!

wfgilman

wfgilman

Oh, ya my b :slight_smile:

Where Next?

Popular in Questions Top

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
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement