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",

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
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
vegabook
I'm brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
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
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
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

Other popular topics Top

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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
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
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 47849 226
New

We're in Beta

About us Mission Statement