Current section
2 Versions
Jump to
Current section
2 Versions
Compare versions
4
files changed
+50
additions
-24
deletions
| @@ -1,16 +1,18 @@ | |
| 1 1 | # LoggerDatadogBackend |
| 2 2 | |
| 3 | - **TODO: Add description** |
| 3 | + A simple backend for ExLogger that increment a counter for the log level triggered. |
| 4 | + |
| 5 | + Useful to keep an eye on your application and add alerting based on changes in error frequencies. |
| 4 6 | |
| 5 7 | ## Installation |
| 6 8 | |
| 7 | - If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: |
| 9 | + The package can be installed with hex as: |
| 8 10 | |
| 9 11 | 1. Add `logger_datadog_backend` to your list of dependencies in `mix.exs`: |
| 10 12 | |
| 11 13 | ```elixir |
| 12 14 | def deps do |
| 13 | - [{:logger_datadog_backend, "~> 0.1.0"}] |
| 15 | + [{:logger_datadog_backend, "~> 0.1"}] |
| 14 16 | end |
| 15 17 | ``` |
| 16 18 | |
| @@ -21,4 +23,33 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed | |
| 21 23 | [applications: [:logger_datadog_backend]] |
| 22 24 | end |
| 23 25 | ``` |
| 26 | + ## Configuration |
| 24 27 | |
| 28 | + This library depends on [ex_statsd](https://hex.pm/packages/ex_statsd). So make sure to include |
| 29 | + the configuration for that library or it won't work. Here is an example: |
| 30 | + |
| 31 | + ```elixir |
| 32 | + use Mix.Config |
| 33 | + |
| 34 | + # ex_statsd configuration |
| 35 | + config :ex_statsd, |
| 36 | + host: "your.statsd.host.com", |
| 37 | + port: 1234, |
| 38 | + namespace: "your-app" |
| 39 | + |
| 40 | + # ex_logger configuration |
| 41 | + config :logger, |
| 42 | + backends: [:console, LoggerDatadogBackend] # for production you can also disable the :console backend |
| 43 | + |
| 44 | + # logger_datadog_backend configuration |
| 45 | + config :logger, LoggerDatadogBackend, |
| 46 | + level: :warn # minimum level to report to datadog |
| 47 | + ``` |
| 48 | + |
| 49 | + ## How it works |
| 50 | + |
| 51 | + the backend will listen to every logger message in your application and report the level on datadog as a counter. |
| 52 | + With the configuration above the counter will be: |
| 53 | + |
| 54 | + - your-app.logger.warn |
| 55 | + - your-app.logger.error |
| @@ -15,4 +15,4 @@ | |
| 15 15 | {<<"name">>,<<"ex_statsd">>}, |
| 16 16 | {<<"optional">>,false}, |
| 17 17 | {<<"requirement">>,<<">= 0.5.1">>}]]}. |
| 18 | - {<<"version">>,<<"0.1.0">>}. |
| 18 | + {<<"version">>,<<"0.1.1">>}. |
| @@ -6,9 +6,7 @@ defmodule LoggerDatadogBackend do | |
| 6 6 | |
| 7 7 | defstruct [level: nil, enabled: false] |
| 8 8 | |
| 9 | - @doc """ |
| 10 | - initialization |
| 11 | - """ |
| 9 | + @doc false |
| 12 10 | def init(__MODULE__) do |
| 13 11 | config = Application.get_env(:logger, __MODULE__) |
| 14 12 | enabled = case Code.ensure_loaded(ExStatsD) do |
| @@ -19,9 +17,7 @@ defmodule LoggerDatadogBackend do | |
| 19 17 | {:ok, init(config, %__MODULE__{enabled: enabled})} |
| 20 18 | end |
| 21 19 | |
| 22 | - @doc """ |
| 23 | - logger event handling |
| 24 | - """ |
| 20 | + @doc false |
| 25 21 | def handle_event({level, _group_leader, {Logger, _message, _timestamp, _metadata}}, state) do |
| 26 22 | %{level: log_level, enabled: enabled} = state |
| 27 23 | cond do |
| @@ -1,33 +1,24 @@ | |
| 1 1 | defmodule LoggerDatadogBackend.Mixfile do |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 | + @version "0.1.1" |
| 5 | + |
| 4 6 | def project do |
| 5 7 | [app: :logger_datadog_backend, |
| 6 | - version: "0.1.0", |
| 8 | + version: @version, |
| 7 9 | elixir: "~> 1.3", |
| 8 10 | build_embedded: Mix.env == :prod, |
| 9 11 | start_permanent: Mix.env == :prod, |
| 10 12 | deps: deps(), |
| 11 13 | description: "a datadog backend for ExLogger", |
| 12 | - package: package] |
| 14 | + package: package(), |
| 15 | + docs: docs()] |
| 13 16 | end |
| 14 17 | |
| 15 | - # Configuration for the OTP application |
| 16 | - # |
| 17 | - # Type "mix help compile.app" for more information |
| 18 18 | def application do |
| 19 19 | [applications: [:logger, :ex_statsd]] |
| 20 20 | end |
| 21 21 | |
| 22 | - # Dependencies can be Hex packages: |
| 23 | - # |
| 24 | - # {:mydep, "~> 0.3.0"} |
| 25 | - # |
| 26 | - # Or git/path repositories: |
| 27 | - # |
| 28 | - # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} |
| 29 | - # |
| 30 | - # Type "mix help deps" for more examples and options |
| 31 22 | defp deps do |
| 32 23 | [{:ex_statsd, ">= 0.5.1"}, |
| 33 24 | {:ex_doc, ">= 0.0.0", only: :dev}] |
| @@ -40,4 +31,12 @@ defmodule LoggerDatadogBackend.Mixfile do | |
| 40 31 | links: %{"GitHub" => "https://github.com/matteosister/logger_datadog_backend"} |
| 41 32 | ] |
| 42 33 | end |
| 34 | + |
| 35 | + defp docs do |
| 36 | + [ |
| 37 | + source_url: "https://github.com/matteosister/logger_datadog_backend", |
| 38 | + source_ref: "v#{@version}", |
| 39 | + extras: ["README.md"], main: "readme" |
| 40 | + ] |
| 41 | + end |
| 43 42 | end |