├── test ├── test_helper.exs └── test_syslog_test.exs ├── .gitignore ├── mix.lock ├── lib ├── test_syslog.ex └── worker.ex ├── mix.exs ├── config └── config.exs └── README.md /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /deps 3 | erl_crash.dump 4 | *.ez 5 | -------------------------------------------------------------------------------- /test/test_syslog_test.exs: -------------------------------------------------------------------------------- 1 | defmodule TestSyslogTest do 2 | use ExUnit.Case 3 | 4 | test "the truth" do 5 | assert 1 + 1 == 2 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{"exprintf": {:package, "0.1.4"}, 2 | "syslog": {:git, "git://github.com/smpallen99/syslog.git", "238722c8227e922dfe531c5478e761ede52a18cf", []}} 3 | -------------------------------------------------------------------------------- /lib/test_syslog.ex: -------------------------------------------------------------------------------- 1 | defmodule TestSyslog do 2 | use Application 3 | 4 | # See http://elixir-lang.org/docs/stable/elixir/Application.html 5 | # for more information on OTP Applications 6 | def start(_type, _args) do 7 | import Supervisor.Spec, warn: false 8 | 9 | # Add the syslog backend 10 | Logger.add_backend Logger.Backends.Syslog 11 | 12 | children = [ 13 | # Define workers and child supervisors to be supervised 14 | worker(TestSyslog.Worker, []) 15 | ] 16 | 17 | # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html 18 | # for other strategies and supported options 19 | opts = [strategy: :one_for_one, name: TestSyslog.Supervisor] 20 | Supervisor.start_link(children, opts) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule TestSyslog.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [app: :test_syslog, 6 | version: "0.0.1", 7 | elixir: "~> 0.15.0", 8 | deps: deps] 9 | end 10 | 11 | # Configuration for the OTP application 12 | # 13 | # Type `mix help compile.app` for more information 14 | def application do 15 | [applications: [:logger, :syslog], 16 | mod: {TestSyslog, []}] 17 | end 18 | 19 | # Dependencies can be hex.pm packages: 20 | # 21 | # {:mydep, "~> 0.3.0"} 22 | # 23 | # Or git/path repositories: 24 | # 25 | # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1"} 26 | # 27 | # Type `mix help deps` for more examples and options 28 | defp deps do 29 | [ 30 | {:syslog, github: "smpallen99/syslog"} 31 | ] 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/worker.ex: -------------------------------------------------------------------------------- 1 | defmodule TestSyslog.Worker do 2 | 3 | use GenServer 4 | require Logger 5 | 6 | def start_link do 7 | GenServer.start_link(__MODULE__, [], name: :worker) 8 | end 9 | 10 | def info(something), do: GenServer.cast(:worker, {:info, something}) 11 | def debug(something), do: GenServer.cast(:worker, {:debug, something}) 12 | def crash, do: GenServer.cast(:worker, :crash) 13 | 14 | def handle_cast({:info, something}, state) do 15 | Logger.info something 16 | {:noreply, state} 17 | end 18 | def handle_cast({:debug, something}, state) do 19 | Logger.debug something 20 | {:noreply, state} 21 | end 22 | def handle_cast(:crash, state) do 23 | Logger.debug "crashing now..." 24 | {:ok, _} = get_crash 25 | {:noreply, state} 26 | end 27 | 28 | defp get_crash, do: :crashing 29 | 30 | end 31 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for third- 9 | # party users, it should be done in your mix.exs file. 10 | 11 | # Sample configuration: 12 | # 13 | # config :logger, 14 | # level: :info, 15 | # format: "$time $metadata[$level] $message\n" 16 | 17 | config :logger, :syslog, [level: :debug, facility: :local1, appid: "exlag"] 18 | 19 | # It is also possible to import configuration files, relative to this 20 | # directory. For example, you can emulate configuration per environment 21 | # by uncommenting the line below and defining dev.exs, test.exs and such. 22 | # Configuration from the imported file will override the ones defined 23 | # here (which is why it is important to import them last). 24 | # 25 | # import_config "#{Mix.env}.exs" 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TestSyslog 2 | ========== 3 | 4 | This is an example project to demonstrate the syslog logger backend 5 | 6 | ## Usage Example 7 | 8 | ``` 9 | [root@ucx20 test_syslog]# iex -S mix 10 | Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false] 11 | Compiled lib/test_syslog.ex 12 | Compiled lib/worker.ex 13 | Generated test_syslog.app 14 | Interactive Elixir (0.15.0) - press Ctrl+C to exit (type h() ENTER for help) 15 | iex(1)> TestSyslog.Worker.info "testing info" 16 | :ok 17 | iex(2)> 20:50:20.880 [info] testing info 18 | iex(2)> TestSyslog.Worker.debug "testing debug" 19 | :ok 20 | iex(3)> 20:50:32.356 [debug] testing debug 21 | iex(3)> TestSyslog.Worker.crash 22 | :ok 23 | iex(4)> 20:50:37.276 [debug] crashing now... 24 | 20:50:37.286 [error] GenServer :worker terminating 25 | Last message: {:"$gen_cast", :crash} 26 | State: [] 27 | ** (exit) an exception was raised: 28 | ** (MatchError) no match of right hand side value: :crashing 29 | (test_syslog) lib/worker.ex:24: TestSyslog.Worker.handle_cast/2 30 | (stdlib) gen_server.erl:599: :gen_server.handle_msg/5 31 | (stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3 32 | 33 | ``` 34 | --------------------------------------------------------------------------------