├── test ├── test_helper.exs └── lumberjack │ ├── source_test.exs │ ├── sources │ ├── socket_test.exs │ └── logger_test.exs │ └── parsers │ └── simple_test.exs ├── .formatter.exs ├── config └── config.exs ├── shell.nix ├── lib ├── lumberjack │ ├── event.ex │ ├── router.ex │ ├── stream.ex │ ├── parser.ex │ ├── application.ex │ ├── sources │ │ ├── socket.ex │ │ ├── file.ex │ │ └── logger.ex │ ├── parsers │ │ └── simple.ex │ └── source.ex └── lumberjack.ex ├── .gitignore ├── .iex.exs ├── mix.exs ├── README.md ├── priv └── assets │ ├── css │ └── main.css │ └── js │ └── main.js ├── mix.lock └── LICENSE /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /.formatter.exs: -------------------------------------------------------------------------------- 1 | # Used by "mix format" 2 | [ 3 | inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] 4 | ] 5 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | import Config 2 | 3 | config :lumberjack, 4 | port: 4000, 5 | sources: [ 6 | Lumberjack.Sources.Logger, 7 | {Lumberjack.Sources.File, dirs: ["log"], parsers: [Lumberjack.Parsers.Simple]}, 8 | {Lumberjack.Sources.Socket, port: 6666, parsers: [Lumberjack.Parsers.Simple]} 9 | ] 10 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | 3 | with pkgs; 4 | with pkgs.beam.packages.erlang; 5 | 6 | mkShell { 7 | buildInputs = [ 8 | elixir 9 | erlang 10 | gitMinimal 11 | ] ++ stdenv.lib.optionals stdenv.isDarwin [ 12 | darwin.apple_sdk.frameworks.CoreFoundation 13 | darwin.apple_sdk.frameworks.CoreServices 14 | ]; 15 | } 16 | -------------------------------------------------------------------------------- /test/lumberjack/source_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Lumberjack.SourceTest do 2 | use ExUnit.Case 3 | 4 | @subject Lumberjack.Source 5 | 6 | doctest @subject 7 | 8 | test "events message pops out in stream" do 9 | stream = @subject.stream() 10 | 11 | @subject.log(%Lumberjack.Event{data: :test}) 12 | 13 | assert [%Lumberjack.Event{data: :test}] = Enum.to_list(Stream.take(stream, 1)) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/lumberjack/event.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Event do 6 | @moduledoc false 7 | 8 | @derive {Jason.Encoder, except: [:type]} 9 | defstruct [:source, :data, :timestamp, type: :log] 10 | 11 | @type t :: %__MODULE__{} 12 | 13 | def to_event(log) do 14 | [ 15 | "event: log\n", 16 | "data: ", Jason.encode_to_iodata!(log), "\n\n" 17 | ] 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /test/lumberjack/sources/socket_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Lumberjack.Sources.SocketTest do 2 | use ExUnit.Case 3 | 4 | @subject Lumberjack.Sources.Socket 5 | 6 | doctest @subject 7 | 8 | describe "udp" do 9 | test "messages sent to socket pop out in stream" do 10 | stream = Lumberjack.stream() 11 | 12 | send_udp("Hello") 13 | 14 | assert [%Lumberjack.Event{data: %{msg: "Hello"}}] = Enum.to_list(Stream.take(stream, 1)) 15 | end 16 | end 17 | 18 | defp send_udp(msg) do 19 | {:ok, socket} = :gen_udp.open(0) 20 | dest = {{127, 0, 0, 1}, 6666} 21 | 22 | :gen_udp.send(socket, dest, msg) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/lumberjack/router.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Router do 6 | @moduledoc false 7 | 8 | use Plug.Router 9 | 10 | plug(Plug.Static, at: "/assets", from: "priv/assets") 11 | 12 | plug(Plug.RequestId) 13 | 14 | plug(Plug.Parsers, 15 | parsers: [:urlencoded, :multipart, :json], 16 | pass: ["*/*"], 17 | json_decoder: Jason 18 | ) 19 | 20 | plug(:match) 21 | plug(:dispatch) 22 | 23 | forward("/", to: Lumberjack) 24 | end 25 | -------------------------------------------------------------------------------- /lib/lumberjack/stream.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Stream do 6 | @moduledoc false 7 | 8 | @name __MODULE__.Registry 9 | 10 | def child_spec(_opts), do: Registry.child_spec(keys: :duplicate, name: @name) 11 | 12 | def register(key), do: Registry.register(@name, key, []) 13 | 14 | def dispatch(key, fun) do 15 | Registry.dispatch(@name, key, fn entries -> 16 | for {pid, _} <- entries, do: fun.(pid) 17 | end) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover/ 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps/ 9 | 10 | # Where third-party dependencies like ExDoc output generated docs. 11 | /doc/ 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | 22 | # Ignore package tarball (built via "mix hex.build"). 23 | lumberjack-*.tar 24 | 25 | -------------------------------------------------------------------------------- /lib/lumberjack/parser.ex: -------------------------------------------------------------------------------- 1 | defmodule Lumberjack.Parser do 2 | @callback parse(input :: binary()) :: {:ok, Lumberjack.Event.t()} | :error 3 | 4 | def parse(data, parsers) do 5 | return = 6 | Enum.reduce_while(parsers, :error, fn parser, _ -> 7 | case parser.parse(data) do 8 | {:ok, parsed} -> {:halt, {:ok, parsed}} 9 | :error -> {:cont, :error} 10 | end 11 | end) 12 | 13 | case return do 14 | {:ok, data} -> data 15 | _ -> %Lumberjack.Event{ 16 | timestamp: :logger.timestamp(), 17 | data: %{ 18 | msg: data, 19 | level: :notice, 20 | meta: %{} 21 | } 22 | } 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/lumberjack/sources/logger_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Lumberjack.Sources.LoggerTest do 2 | use ExUnit.Case 3 | 4 | require Logger 5 | 6 | @subject Lumberjack.Sources.Logger 7 | 8 | doctest @subject 9 | 10 | @tag capture_log: true 11 | test "messages sent to Erlang logger pop out in stream" do 12 | stream = Lumberjack.stream() 13 | 14 | :logger.debug("Hello") 15 | 16 | assert [%Lumberjack.Event{data: %{msg: "Hello", level: :debug}}] = Enum.to_list(Stream.take(stream, 1)) 17 | end 18 | 19 | @tag capture_log: true 20 | test "messages sent to Elixir logger pop out in stream" do 21 | stream = Lumberjack.stream() 22 | 23 | Logger.info("Hello") 24 | 25 | assert [%Lumberjack.Event{data: %{msg: "Hello", level: :info}}] = Enum.to_list(Stream.take(stream, 1)) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/lumberjack/application.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Application do 6 | @moduledoc false 7 | 8 | use Application 9 | 10 | def start(_type, _args) do 11 | port = Application.get_env(:lumberjack, :port) 12 | 13 | children = [ 14 | Lumberjack.Stream, 15 | Lumberjack.Source 16 | ] ++ server(port) 17 | 18 | opts = [strategy: :one_for_one, name: Lumberjack.Supervisor] 19 | 20 | case Supervisor.start_link(children, opts) do 21 | {:ok, _pid} = ok -> 22 | Lumberjack.Source.install() 23 | ok 24 | 25 | err -> 26 | err 27 | end 28 | end 29 | 30 | defp server(nil), do: [] 31 | defp server(port) when is_integer(port) do 32 | [ 33 | {Plug.Cowboy, scheme: :http, port: 4000, plug: Lumberjack.Router} 34 | ] 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /test/lumberjack/parsers/simple_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Lumberjack.Parsers.SimpleTest do 2 | use ExUnit.Case, async: true 3 | 4 | @subject Lumberjack.Parsers.Simple 5 | 6 | doctest @subject 7 | 8 | test "plain message is errors (aka pass through)" do 9 | assert :error == @subject.parse("Foo") 10 | end 11 | 12 | test "level is parsed" do 13 | assert {:ok, parsed} = @subject.parse("[info] Foo") 14 | assert parsed.data.level == :info 15 | end 16 | 17 | test "when invalid level, errors" do 18 | assert :error == @subject.parse("[iinfo] Foo") 19 | assert :error == @subject.parse("[ info] Foo") 20 | end 21 | 22 | test "date time is parsed" do 23 | assert {:ok, parsed} = @subject.parse("2016-04-16T12:34:56.7890Z [info] Foo") 24 | assert parsed.timestamp == 1460810096789000 25 | end 26 | 27 | test "fails on incorrect DT" do 28 | assert :error == @subject.parse("2016-04-16T12:34:5 [info] Foo") 29 | end 30 | 31 | test "trims message" do 32 | assert {:ok, parsed} = @subject.parse("[info] Foo ") 33 | assert parsed.data.msg == "Foo" 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /.iex.exs: -------------------------------------------------------------------------------- 1 | require Logger 2 | 3 | defmodule TestLogger do 4 | require Logger 5 | 6 | def start do 7 | {:ok, socket} = :gen_udp.open(0) 8 | 9 | {:ok, _pid} = Task.start(__MODULE__, :loop, [fn level, msg -> Logger.log(level, msg) end]) 10 | 11 | {:ok, _pid} = 12 | Task.start(__MODULE__, :loop, [ 13 | fn level, msg -> File.write!("log/example.log", ["[#{level}]", msg, ?\n], [:append]) end 14 | ]) 15 | 16 | {:ok, _pid} = 17 | Task.start(__MODULE__, :loop, [ 18 | fn level, msg -> :gen_udp.send(socket, {{127, 0, 0, 1}, 6666}, ["[#{level}]", msg]) end 19 | ]) 20 | end 21 | 22 | def loop(f), do: loop(f, 0) 23 | 24 | defp loop(f, n) do 25 | f.(pick_level(), "Message #{n}") 26 | 27 | Process.sleep(Enum.random(200..2000)) 28 | 29 | loop(f, n + 1) 30 | end 31 | 32 | defp pick_level, do: pick_level(Enum.random(0..159)) 33 | 34 | defp pick_level(n) when n in 0..39, do: :debug 35 | defp pick_level(n) when n in 40..79, do: :info 36 | defp pick_level(n) when n in 80..119, do: :notice 37 | defp pick_level(n) when n in 120..134, do: :warning 38 | defp pick_level(n) when n in 135..149, do: :error 39 | defp pick_level(n) when n in 150..154, do: :critical 40 | defp pick_level(n) when n in 155..158, do: :alert 41 | defp pick_level(_), do: :emergency 42 | end 43 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule Lumberjack.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :lumberjack, 7 | version: "0.1.0", 8 | elixir: "~> 1.10", 9 | start_permanent: Mix.env() == :prod, 10 | deps: deps(), 11 | docs: docs(), 12 | package: package() 13 | ] 14 | end 15 | 16 | # Run "mix help compile.app" to learn about applications. 17 | def application do 18 | [ 19 | extra_applications: [:logger], 20 | mod: {Lumberjack.Application, []}, 21 | env: [ 22 | sources: [Lumberjack.Sources.Logger] 23 | ] 24 | ] 25 | end 26 | 27 | defp package do 28 | [ 29 | description: "Web based log viewer for Elixir applications", 30 | licenses: ~w[MPL-2.0], 31 | links: %{ 32 | "GitHub" => "https://github.com/hauleth/lumberjack" 33 | } 34 | ] 35 | end 36 | 37 | defp docs do 38 | [ 39 | groups_for_modules: [ 40 | Sources: ~r/^Lumberjack\.Sources\./, 41 | Parsers: ~r/^Lumberjack\.Parsers\./ 42 | ] 43 | ] 44 | end 45 | 46 | # Run "mix help deps" to learn about dependencies. 47 | defp deps do 48 | [ 49 | {:plug_cowboy, "~> 2.0"}, 50 | {:jason, "~> 1.0"}, 51 | {:file_system, "~> 0.2 or ~> 1.0"}, 52 | 53 | {:ex_doc, ">= 0.0.0", only: :dev} 54 | ] 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/lumberjack/sources/socket.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Sources.Socket do 6 | use GenServer 7 | 8 | @behaviour Lumberjack.Source 9 | 10 | @doc false 11 | def install(opts) do 12 | type = Keyword.get(opts, :type, :udp) 13 | port = Keyword.fetch!(opts, :port) 14 | parsers = Keyword.get(opts, :parsers, []) 15 | 16 | {:ok, _pid} = 17 | Lumberjack.Source.start_child({__MODULE__, %{type: type, port: port, parsers: parsers}}) 18 | 19 | :ok 20 | end 21 | 22 | @doc false 23 | def start_link(opts), do: GenServer.start_link(__MODULE__, opts) 24 | 25 | @doc false 26 | def init(%{type: type, port: port, parsers: parsers}) do 27 | {:ok, socket} = socket(type, port) 28 | 29 | {:ok, %{socket: socket, name: name(type, port), parsers: parsers}} 30 | end 31 | 32 | def handle_info( 33 | {:udp, socket, _ip, _port, data}, 34 | %{socket: socket, name: name, parsers: parsers} = state 35 | ) do 36 | event = 37 | data 38 | |> Lumberjack.Parser.parse(parsers) 39 | |> struct(source: name) 40 | 41 | Lumberjack.Source.log(event) 42 | 43 | {:noreply, state} 44 | end 45 | 46 | defp socket(:udp, port), do: :gen_udp.open(port, [:binary]) 47 | 48 | defp name(:udp, port), do: "UDP #{port}" 49 | defp name(:tcp, port), do: "TCP #{port}" 50 | end 51 | -------------------------------------------------------------------------------- /lib/lumberjack/parsers/simple.ex: -------------------------------------------------------------------------------- 1 | defmodule Lumberjack.Parsers.Simple do 2 | @regex ~r/^(?\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d+)?Z)?\s*(\[(?\w+)\])?(?.*)$/m 3 | 4 | def parse(input) do 5 | with %{"msg" => msg} = matches <- Regex.named_captures(@regex, input), 6 | {:ok, ts} <- date(matches), 7 | {:ok, level} <- level(matches) 8 | do 9 | {:ok, %Lumberjack.Event{ 10 | timestamp: ts, 11 | data: %{ 12 | msg: String.trim(msg), 13 | level: level, 14 | meta: %{} 15 | } 16 | }} 17 | else 18 | _ -> :error 19 | end 20 | end 21 | 22 | defp date(%{"date" => str}) when is_binary(str) do 23 | with {:ok, datetime, _} <- DateTime.from_iso8601(str) do 24 | {:ok, DateTime.to_unix(datetime, :microsecond)} 25 | else 26 | _ -> {:ok, :logger.timestamp()} 27 | end 28 | end 29 | 30 | defp date(_), do: :logger.timestamp() 31 | 32 | defp level(%{"level" => level}) when is_binary(level), do: do_level(String.downcase(level)) 33 | defp level(_), do: :error 34 | 35 | defp do_level("debug"), do: {:ok, :debug} 36 | defp do_level("info"), do: {:ok, :info} 37 | defp do_level("notice"), do: {:ok, :notice} 38 | defp do_level("warning"), do: {:ok, :warning} 39 | defp do_level("warn"), do: {:ok, :warning} 40 | defp do_level("error"), do: {:ok, :error} 41 | defp do_level("critical"), do: {:ok, :critical} 42 | defp do_level("alert"), do: {:ok, :alert} 43 | defp do_level("emergency"), do: {:ok, :emergency} 44 | 45 | 46 | defp do_level(_), do: :error 47 | end 48 | -------------------------------------------------------------------------------- /lib/lumberjack/source.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Source do 6 | @moduledoc """ 7 | Definition of the log message source 8 | """ 9 | 10 | @supervisor __MODULE__.Supervisor 11 | 12 | @key __MODULE__ 13 | 14 | @callback install(opts :: keyword()) :: :ok | {:error, term()} 15 | 16 | @doc """ 17 | Dispatch log message 18 | """ 19 | def log(event) do 20 | Lumberjack.Stream.dispatch(@key, &send(&1, event)) 21 | end 22 | 23 | @doc false 24 | def child_spec(_opts), 25 | do: DynamicSupervisor.child_spec(strategy: :one_for_one, name: @supervisor) 26 | 27 | @doc false 28 | def start_child(child_spec), do: DynamicSupervisor.start_child(@supervisor, child_spec) 29 | 30 | @doc false 31 | def stream do 32 | Lumberjack.Stream.register(@key) 33 | 34 | Stream.resource( 35 | fn -> :ok end, 36 | fn _ -> 37 | receive do 38 | %Lumberjack.Event{} = msg -> {[msg], :ok} 39 | end 40 | end, 41 | fn _ -> :ok end 42 | ) 43 | end 44 | 45 | # Install all sources defined in the application configuration 46 | @doc false 47 | def install do 48 | :lumberjack 49 | |> Application.fetch_env!(:sources) 50 | |> Enum.each(&install_source/1) 51 | end 52 | 53 | defp install_source({mod, opts}) when is_atom(mod) do 54 | :ok = mod.install(opts) 55 | end 56 | 57 | defp install_source(mod) when is_atom(mod) do 58 | :ok = mod.install([]) 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lumberjack 2 | 3 | Application for providing nice UI for logs, especially in development. The idea 4 | is to allow for digesting data from different sources, not only Erlang Logger. 5 | 6 | [![Showcase](https://img.youtube.com/vi/Bd5MDVkfDGE/0.jpg)](https://www.youtube.com/watch?v=Bd5MDVkfDGE) 7 | 8 | ## Goals 9 | 10 | The intended use case is to have single place to view logs from all components 11 | of your application, so not only Erlang/Elixir logs, but for example also DB 12 | logs. 13 | 14 | ## Installation 15 | 16 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed 17 | by adding `lumberjack` to your list of dependencies in `mix.exs`: 18 | 19 | ```elixir 20 | def deps do 21 | [ 22 | {:lumberjack, "~> 0.1.0"} 23 | ] 24 | end 25 | ``` 26 | 27 | Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) 28 | and published on [HexDocs](https://hexdocs.pm). Once published, the docs can 29 | be found at [https://hexdocs.pm/lumberjack](https://hexdocs.pm/lumberjack). 30 | 31 | ## Configuration 32 | 33 | ```elixir 34 | config :lumberjack, 35 | sources: [ 36 | Lumberjack.Sources.Logger, 37 | {Lumberjack.Sources.File, dirs: ["logs"]}, 38 | {Lumberjack.Sources.Socket, type: :udp, port: 7777} 39 | ] 40 | ``` 41 | 42 | ## TODO 43 | 44 | - ~~Web UI via SSE or WebSockets (to be decided later, but I am in favour of SSE)~~ 45 | - Parsers for the incoming messages, so it will be possible to extract levels 46 | out of the messages incoming from external sources 47 | - Fix bugs in file source (missing first message, missing messages on rotation) 48 | - Filtering incoming messages 49 | - Way to check metadata of the logged message 50 | 51 | ## License 52 | 53 | [MPL-2.0](LICENSE) 54 | -------------------------------------------------------------------------------- /lib/lumberjack/sources/file.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Sources.File do 6 | use GenServer 7 | 8 | @behaviour Lumberjack.Source 9 | 10 | @doc false 11 | def install(opts) do 12 | dirs = Keyword.fetch!(opts, :dirs) 13 | parsers = Keyword.get(opts, :parsers, []) 14 | 15 | {:ok, _pid} = Lumberjack.Source.start_child({__MODULE__, %{ 16 | dirs: dirs, 17 | parsers: parsers 18 | }}) 19 | 20 | :ok 21 | end 22 | 23 | @doc false 24 | def start_link(args), do: GenServer.start_link(__MODULE__, args) 25 | 26 | @doc false 27 | def init(%{dirs: dirs, parsers: parsers}) do 28 | {:ok, watcher_pid} = FileSystem.start_link(dirs: dirs) 29 | FileSystem.subscribe(watcher_pid) 30 | 31 | {:ok, %{watcher_pid: watcher_pid, streams: %{}, parsers: parsers}} 32 | end 33 | 34 | @doc false 35 | def handle_info( 36 | {:file_event, wpid, {path, _events}}, 37 | %{watcher_pid: wpid, streams: streams, parsers: parsers} = state 38 | ) do 39 | stream = 40 | Map.get_lazy(streams, path, fn -> 41 | file = File.open!(path, ~w[read]a) 42 | :file.position(file, :eof) 43 | 44 | file 45 | end) 46 | 47 | data = String.split(IO.read(stream, :all), ~r/\n+/, trim: true) 48 | 49 | for entry <- data do 50 | parsed = 51 | entry 52 | |> Lumberjack.Parser.parse(parsers) 53 | |> struct(source: path) 54 | 55 | Lumberjack.Source.log(parsed) 56 | end 57 | 58 | {:noreply, %{state | streams: Map.put(streams, path, stream)}} 59 | end 60 | 61 | def handle_info({:file_event, wpid, :stop}, %{watcher_pid: wpid} = state) do 62 | {:stop, :watcher_stopped, state} 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /priv/assets/css/main.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --dark: #333; 3 | --light: #bbb; 4 | 5 | --background: var(--dark); 6 | --text: var(--light); 7 | 8 | --ui: 0.6; 9 | 10 | --highlight: #39409b; 11 | --debug: #399b95; 12 | --warning: #9b9539; 13 | --error: #9b3940; 14 | } 15 | 16 | .light { 17 | --background: var(--light); 18 | --text: var(--dark); 19 | } 20 | 21 | /* Colours */ 22 | 23 | .debug { 24 | color: var(--debug); 25 | } 26 | 27 | .warning { 28 | color: var(--warning); 29 | } 30 | 31 | .error { 32 | color: var(--error); 33 | } 34 | 35 | .critical, .alert, .emergency { 36 | background-color: var(--error); 37 | color: var(--dark); 38 | } 39 | 40 | /* General */ 41 | 42 | body { 43 | font-family: monospace; 44 | color: var(--text); 45 | background-color: var(--background); 46 | 47 | margin: 0; 48 | padding: 0 0 3.5rem 0; 49 | } 50 | 51 | .ui { 52 | background-color: var(--background); 53 | filter: brightness(var(--ui)); 54 | } 55 | 56 | table { 57 | width: 100%; 58 | text-align: left; 59 | border-collapse: collapse; 60 | cursor: default; 61 | } 62 | 63 | th { 64 | position: -webkit-sticky; 65 | position: sticky; 66 | top: 0; 67 | padding: .5rem; 68 | } 69 | 70 | tbody td { 71 | padding: .15rem .5rem; 72 | vertical-align: top; 73 | } 74 | 75 | tbody tr:hover { 76 | font-weight: bold; 77 | } 78 | 79 | table .src { width: 10em; text-align: right; display: none; } 80 | table .tms { width: 15em; } 81 | table .lvl { width: 6em; } 82 | 83 | .navigation { 84 | position: fixed; 85 | bottom: 0; 86 | width: 100%; 87 | padding: 1rem; 88 | display: block; 89 | } 90 | 91 | label { 92 | -webkit-user-select: none; 93 | user-select: none; 94 | } 95 | 96 | .modal { 97 | padding: 1em; 98 | overflow: auto; 99 | position: fixed; 100 | top: 0; 101 | right: 0; 102 | width: 20%; 103 | height: 100%; 104 | } 105 | -------------------------------------------------------------------------------- /lib/lumberjack.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack do 6 | @moduledoc """ 7 | Documentation for `Lumberjack`. 8 | """ 9 | 10 | @html """ 11 | 12 | 13 | I am lumberjack, and I am ok! 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
SourceTimeLevelMessage
29 | 34 | 35 | 36 | 37 | """ 38 | 39 | use Plug.Router 40 | 41 | plug(:match) 42 | plug(:dispatch) 43 | 44 | get "/" do 45 | conn 46 | |> put_resp_content_type("text/html") 47 | |> send_resp(200, @html) 48 | end 49 | 50 | get "/stream" do 51 | conn = 52 | conn 53 | |> put_resp_header("cache-control", "no-cache") 54 | |> put_resp_content_type("text/event-stream") 55 | |> send_chunked(200) 56 | 57 | Enum.reduce_while(Lumberjack.stream(), conn, fn msg, conn -> 58 | case chunk(conn, Lumberjack.Event.to_event(msg)) do 59 | {:ok, conn} -> {:cont, conn} 60 | {:error, :closed} -> {:halt, conn} 61 | end 62 | end) 63 | end 64 | 65 | defdelegate stream, to: Lumberjack.Source 66 | end 67 | -------------------------------------------------------------------------------- /lib/lumberjack/sources/logger.ex: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | 5 | defmodule Lumberjack.Sources.Logger do 6 | @default_formatter {:logger_formatter, 7 | %{ 8 | single_line: false, 9 | template: [:msg] 10 | }} 11 | 12 | @moduledoc """ 13 | Extract messages from Erlang logger. 14 | 15 | ## Options 16 | 17 | - `formatter` - how to format message before sending it to the UI. 18 | It should be tuple in form of `{format_module, options_map}`. Defaults 19 | to `#{inspect(@default_formatter)}` 20 | """ 21 | @behaviour Lumberjack.Source 22 | 23 | @doc false 24 | def install(opts) do 25 | formatter = Keyword.get(opts, :formatter, @default_formatter) 26 | 27 | :ok = 28 | :logger.add_handler(Lumberjack, Lumberjack.Sources.Logger, %{ 29 | formatter: formatter 30 | }) 31 | 32 | :ok 33 | end 34 | 35 | @doc false 36 | def log(%{level: level, meta: meta} = event, %{formatter: {fmod, opts}}) do 37 | {ts, meta} = Map.pop!(meta, :time) 38 | 39 | msg = 40 | event 41 | |> fmod.format(opts) 42 | |> to_string() 43 | 44 | encoded = encode(meta) 45 | 46 | Lumberjack.Source.log(%Lumberjack.Event{ 47 | timestamp: ts, 48 | source: :logger, 49 | data: %{ 50 | msg: msg, 51 | level: level, 52 | meta: encoded 53 | } 54 | }) 55 | end 56 | 57 | defp encode(meta) when is_map(meta), do: Map.new(meta, &encode_keys/1) 58 | 59 | defp encode(data) when is_binary(data) when is_number(data) when is_atom(data), 60 | do: data 61 | 62 | defp encode(list) when is_list(list) do 63 | cond do 64 | Keyword.keyword?(list) -> Map.new(list, &encode_keys/1) 65 | List.ascii_printable?(list) -> List.to_string(list) 66 | true -> for elem <- list, do: encode(elem) 67 | end 68 | end 69 | 70 | defp encode(data), do: inspect(data) 71 | 72 | defp encode_keys({key, value}), do: {to_string(key), encode(value)} 73 | end 74 | -------------------------------------------------------------------------------- /priv/assets/js/main.js: -------------------------------------------------------------------------------- 1 | // Message handling 2 | 3 | const evtSrc = new EventSource('/stream') 4 | const $logs = document.getElementById('logs') 5 | const $autoscroll = document.getElementById('autoscroll') 6 | 7 | let id = undefined 8 | 9 | const createRow = function (data) { 10 | const $row = document.createElement('tr') 11 | 12 | for (const entry of data) { 13 | const $column = document.createElement('td') 14 | const classes = entry.classes || [] 15 | $column.classList.add(...classes) 16 | $column.innerText = entry.data 17 | $row.appendChild($column) 18 | } 19 | 20 | return $row; 21 | } 22 | 23 | evtSrc.addEventListener('log', (event) => { 24 | const log = JSON.parse(event.data) 25 | const time = new Date(log.timestamp/1000) 26 | 27 | const $row = createRow([ 28 | {classes: ['src'], data: log.source}, 29 | {classes: ['tms'], data: time.toTimeString()}, 30 | {classes: ['lvl'], data: log.data.level}, 31 | {classes: ['msg'], data: log.data.msg} 32 | ]) 33 | 34 | $row.dataset.metadata = JSON.stringify(log.data.meta) 35 | $row.classList.add(log.data.level) 36 | $logs.appendChild($row) 37 | 38 | if ($autoscroll.checked) { 39 | if (id) window.cancelAnimationFrame(id) 40 | 41 | id = window.requestAnimationFrame(() => { 42 | window.scrollTo(0, document.body.scrollHeight) 43 | $autoscroll.checked = true 44 | }) 45 | } 46 | }) 47 | 48 | // Show/hide sources 49 | 50 | const $style = document.createElement('style') 51 | const $showSources = document.getElementById('show_sources') 52 | 53 | document.head.appendChild($style) 54 | 55 | $showSources.addEventListener('change', () => { 56 | if (!$showSources.checked && $style.sheet.rules[0]) { 57 | $style.sheet.deleteRule(0) 58 | } else { 59 | $style.sheet.insertRule('table .src { display: table-cell; }', 0) 60 | } 61 | }) 62 | 63 | // Theme toggle 64 | 65 | const $light = document.getElementById('light') 66 | 67 | $light.addEventListener('change', () => { 68 | if ($light.checked) { 69 | document.body.classList.add('light') 70 | } else { 71 | document.body.classList.remove('light') 72 | } 73 | }) 74 | 75 | // Modal 76 | 77 | const $modal = document.getElementById('modal') 78 | const $json = document.createElement('pre') 79 | 80 | $modal.appendChild($json) 81 | 82 | $modal.addEventListener('click', () => $modal.hidden = true) 83 | 84 | $logs.addEventListener('click', event => { 85 | const meta = JSON.parse(event.target.parentNode.dataset.metadata) 86 | 87 | $modal.hidden = false 88 | $json.innerText = JSON.stringify(meta, null, 2) 89 | }) 90 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "cowboy": {:hex, :cowboy, "2.13.0", "09d770dd5f6a22cc60c071f432cd7cb87776164527f205c5a6b0f24ff6b38990", [:make, :rebar3], [{:cowlib, ">= 2.14.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "e724d3a70995025d654c1992c7b11dbfea95205c047d86ff9bf1cda92ddc5614"}, 3 | "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, 4 | "cowlib": {:hex, :cowlib, "2.14.0", "623791c56c1cc9df54a71a9c55147a401549917f00a2e48a6ae12b812c586ced", [:make, :rebar3], [], "hexpm", "0af652d1550c8411c3b58eed7a035a7fb088c0b86aff6bc504b0bc3b7f791aa2"}, 5 | "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, 6 | "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"}, 7 | "ex_doc": {:hex, :ex_doc, "0.37.3", "f7816881a443cd77872b7d6118e8a55f547f49903aef8747dbcb345a75b462f9", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "e6aebca7156e7c29b5da4daa17f6361205b2ae5f26e5c7d8ca0d3f7e18972233"}, 8 | "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, 9 | "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, 10 | "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, 11 | "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, 12 | "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, 13 | "mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"}, 14 | "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, 15 | "phoenix": {:hex, :phoenix, "1.4.16", "2cbbe0c81e6601567c44cc380c33aa42a1372ac1426e3de3d93ac448a7ec4308", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "856cc1a032fa53822737413cf51aa60e750525d7ece7d1c0576d90d7c0f05c24"}, 16 | "phoenix_html": {:hex, :phoenix_html, "2.14.1", "7dabafadedb552db142aacbd1f11de1c0bbaa247f90c449ca549d5e30bbc66b4", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "536d5200ad37fecfe55b3241d90b7a8c3a2ca60cd012fc065f776324fa9ab0a9"}, 17 | "phoenix_live_view": {:hex, :phoenix_live_view, "0.10.0", "5cb089e483ac9f33c1eeba51f24a395de5966d3a9f3f204b0bb9a5a938f2a695", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.4.16", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "236b1ba30062ee7a9786bf2306efecb01fc3bd86be199fbb66318c19f24a37e7"}, 18 | "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.2", "496c303bdf1b2e98a9d26e89af5bba3ab487ba3a3735f74bf1f4064d2a845a3e", [:mix], [], "hexpm", "1f13f9f0f3e769a667a6b6828d29dec37497a082d195cc52dbef401a9b69bf38"}, 19 | "plug": {:hex, :plug, "1.17.0", "a0832e7af4ae0f4819e0c08dd2e7482364937aea6a8a997a679f2cbb7e026b2e", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f6692046652a69a00a5a21d0b7e11fcf401064839d59d6b8787f23af55b1e6bc"}, 20 | "plug_cowboy": {:hex, :plug_cowboy, "2.7.3", "1304d36752e8bdde213cea59ef424ca932910a91a07ef9f3874be709c4ddb94b", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "77c95524b2aa5364b247fa17089029e73b951ebc1adeef429361eab0bb55819d"}, 21 | "plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"}, 22 | "ranch": {:hex, :ranch, "2.2.0", "25528f82bc8d7c6152c57666ca99ec716510fe0925cb188172f41ce93117b1b0", [:make, :rebar3], [], "hexpm", "fa0b99a1780c80218a4197a59ea8d3bdae32fbff7e88527d7d8a4787eff4f8e7"}, 23 | "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, 24 | } 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. --------------------------------------------------------------------------------