Timber v1.0.13 Timber.Integrations.EctoLogger
Timber integration for Ecto.
Timber can hook into Ecto’s logging system to gather information
about queries including the text of the query and the time
it took to execute. This information is then logged as a
Timber.Events.SQLQueryEvent
.
To install Timber’s Ecto event collector, you only need to modify the
application configuration on a per-repository basis. Each repository
has a configuration key :loggers
that accepts a list of three element
tuples where each tuple describes a log event consumer. If you do not
have a :loggers
key specified, Ecto uses the default list of
[{Ecto.LogEntry, :log, []}]
which tells the repository to log every
event to Ecto.LogEntry.log/1
. In order to avoid duplicate logging,
you will want to make sure it isn’t in the list when using this
event collector.
The tuple for Timber’s event collector is {Timber.Integrations.EctoLogger, :log, []}
.
Many applications will have only one repository named Repo
, which
makes adding this easy. For example, to add it to the repository
MyApp.Repo
:
config :my_app, MyApp.Repo,
loggers: [{Timber.Integrations.EctoLogger, :log, []}]
By default, queries are logged at the :debug
level. If you want
to use a custom level, simple add it to the list of arguments.
For example, to log every query at the :info
level:
config :my_app, MyApp.Repo,
loggers: [{Timber.Integrations.EctoLogger, :log, [:info]}]
Timing
The time reported in the event is the amount of time the query took to execute on the database, as measured by Ecto. It does not include the time that the query spent in the pool’s queue or the time spent decoding the response from the database.
Summary
Functions
Identical to log/2 except that it uses a default level of :debug
Takes an Ecto.LogEntry
struct and logs it as a Timber.Event.SQLQueryEvent
event at the designated level
Functions
Identical to log/2 except that it uses a default level of :debug
Takes an Ecto.LogEntry
struct and logs it as a Timber.Event.SQLQueryEvent
event at the designated level
This function is designed to be called from Ecto’s built-in logging
system (see the module’s documentation). It takes an Ecto.LogEntry
entry struct and parses it into a Timber.Event.SQLQueryEvent
which is then logged at the designated level.