Packages
timber
1.1.10
3.1.2
3.1.1
3.1.0
3.0.0
3.0.0-alpha.3
3.0.0-alpha.2
3.0.0-alpha.1
2.8.4
2.8.3
2.8.2
2.8.1
2.8.0
2.7.0
2.6.1
2.6.0
2.5.6
2.5.5
2.5.4
2.5.3
2.5.2
2.5.1
2.5.0
2.4.5
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.4
2.3.3
2.3.1
2.3.0
2.2.1
2.2.0
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.2
2.0.1
2.0.0
2.0.0-rc7
2.0.0-rc6
2.0.0-rc5
2.0.0-rc4
2.0.0-rc3
2.0.0-rc2
2.0.0-rc1
1.1.18
1.1.17
1.1.16
1.1.15
1.1.14
1.1.13
1.1.12
1.1.11
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.16
1.0.15
1.0.14
1.0.13
1.0.12
1.0.11
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.3
0.2.2
0.2.1
0.2.0
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
🌲 Great Elixir Logging Made Easy. Official Timber.io Integration.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/timber/install/config_file.ex
defmodule Mix.Tasks.Timber.Install.ConfigFile do
alias Mix.Tasks.Timber.Install.{FileHelper, IOHelper}
@file_name "timber.exs"
@file_path Path.join(["config", @file_name])
# Adds the config/timber.exs file to be linked in config/config.exs
def create!(%{mix_name: mix_name, endpoint_module_name: endpoint_module_name,
repo_module_name: repo_module_name} = application)
do
contents =
"""
use Mix.Config
"""
contents =
if endpoint_module_name do
contents <>
"""
# Update the instrumenters so that we can structure Phoenix logs
config :#{mix_name}, #{endpoint_module_name},
instrumenters: [Timber.Integrations.PhoenixInstrumenter]
"""
else
contents
end
contents =
if repo_module_name do
contents <>
"""
# Structure Ecto logs
config :#{mix_name}, #{repo_module_name},
loggers: [{Timber.Integrations.EctoLogger, :log, [:info]}]
"""
else
contents
end
contents = contents <>
"""
# Use Timber as the logger backend
# Feel free to add additional backends if you want to send you logs to multiple devices.
config :logger,
backends: [Timber.LoggerBackend]
#{timber_portion(application)}
# For dev / test environments, always log to STDOUt and format the logs properly
if Mix.env() == :dev || Mix.env() == :test do
config :timber, transport: Timber.Transports.IODevice
config :timber, :io_device,
colorize: true,
format: :logfmt,
print_timestamps: true,
print_log_level: true,
print_metadata: false # turn this on to view the additiional metadata
end
# Need help?
# Email us: support@timber.io
# File an issue: https://github.com/timberio/timber-elixir/issues
"""
FileHelper.write!(@file_path, contents)
end
defp timber_portion(%{platform_type: "heroku"}) do
"""
# Direct logs to STDOUT for Heroku. We'll use Heroku drains to deliver logs.
config :timber,
transport: Timber.Transports.IODevice
"""
end
defp timber_portion(%{api_key: api_key}) do
"""
# Deliver logs via HTTP to the Timber API
config :timber,
transport: Timber.Transports.HTTP,
api_key: #{api_key_portion(api_key)},
http_client: Timber.Transports.HTTP.HackneyClient
"""
end
defp api_key_portion(api_key) do
"""
How would you prefer to store your Timber API key?
1) In the TIMBER_LOGS_KEY environment variable
2) Inline within the #{@file_path} file
"""
|> IOHelper.puts()
case IOHelper.ask("Enter your choice (1/2)") do
"1" -> "{:system, \"TIMBER_LOGS_KEY\"}"
"2" -> "\"#{api_key}\""
other ->
"Sorry #{inspect(other)} is not a valid input. Please try again."
|> IOHelper.puts(:red)
api_key_portion(api_key)
end
end
def file_path, do: @file_path
def link!(config_file_path) do
contents =
"""
# Import Timber, structured logging
import_config \"#{@file_name}\"
"""
FileHelper.append_once!(config_file_path, contents)
end
end