Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc doc changes #24

Merged
merged 9 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The MIT License (MIT)
# The MIT License (MIT)

Copyright (c) 2015 Jonathan Clem

Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
# Logfmt [![Build Status](https://github.com/jclem/logfmt-elixir/workflows/CI/badge.svg)](https://github.com/jclem/logfmt-elixir/actions?workflow=CI)
# Logfmt

[![Build Status](https://github.com/jclem/logfmt-elixir/workflows/CI/badge.svg)](https://github.com/jclem/logfmt-elixir/actions?workflow=CI)
[![Module Version](https://img.shields.io/hexpm/v/logfmt.svg)](https://hex.pm/packages/logfmt)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/logfmt/)
[![Total Download](https://img.shields.io/hexpm/dt/logfmt.svg)](https://hex.pm/packages/logfmt)
[![License](https://img.shields.io/hexpm/l/logfmt.svg)](https://github.com/jclem/logfmt-elixir/blob/master/LICENSE.md)
[![Last Updated](https://img.shields.io/github/last-commit/jclem/logfmt-elixir.svg)](https://github.com/jclem/logfmt-elixir/commits/master)

Logfmt is a module for encoding and decoding logfmt-style log lines.

## Installation

The package can be installed by adding `:logfmt` to your list of dependencies in
`mix.exs`:

```elixir
def deps do
[
{:logfmt, "~> 3.3"}
]
end
```

## Usages

Decode log lines into maps:

Expand All @@ -17,7 +41,7 @@ iex> Logfmt.encode %{foo: "bar"}
"foo=bar"
```

Custom types can encoded by implementing the ValueEncoder procotol for it.
Custom types can encoded by implementing the ValueEncoder protocol for it.

For example to encode DateTime and NaiveDateTime and implementation could look like this:

Expand Down Expand Up @@ -72,4 +96,4 @@ involves converting user strings into non-garbage-collected atoms.
Now, this module decodes into maps only (with string keys) and encodes any Dict
implementation type. This is a fair compromise, because ordering upon decoding a
Logfmt line is not important, and keeping only the last value for a duplicate
key in a log line is fair, as well.
key in a log line is fair, as well.
17 changes: 10 additions & 7 deletions lib/logfmt.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Logfmt do
@moduledoc """
Decodes and encodes logfmt-style log lines
Decodes and encodes logfmt-style log lines.

In [logfmt][logfmt]-style log lines, data is encoded as a string of
`"key-value"` pairs. Logfmt can encode a `Dict` into a string in this format,
Expand All @@ -13,7 +13,7 @@ defmodule Logfmt do
"""

@doc ~S"""
Decodes the given line into a map
Decodes the given line into a map.

## Examples

Expand All @@ -28,20 +28,22 @@ defmodule Logfmt do

iex> Logfmt.decode "foo=1"
%{"foo" => 1}

"""
@spec decode(String.t()) :: map
def decode(string) do
Logfmt.Decoder.decode(string)
end

@doc ~S"""
Encodes the given Dict into a Logfmt-style line
Encodes the given Dict into a Logfmt-style line.

Optionally a list of options can be given to change the encode behaviour.

Optionally a list of options can be given to change the encode behaviour
## Options

Options:
* `output` - if set to :iolist, an iolist is returned,
any other value will return a binary
* `output` - if set to `:iolist`, an iolist is returned, any other value
will return a binary

## Examples

Expand All @@ -56,6 +58,7 @@ defmodule Logfmt do

iex> Logfmt.encode [foo: "bar baz"], [output: :iolist]
[["foo", "=", ["\"", "bar baz", "\""]]]

"""
@spec encode(Dict.t(), options :: Keyword.t()) :: String.t()
def encode(list, options \\ []) do
Expand Down
1 change: 1 addition & 0 deletions lib/logfmt/decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Logfmt.Decoder do

iex> Logfmt.decode "foo=true"
%{"foo" => true}

"""
import String, only: [next_grapheme: 1]

Expand Down
1 change: 1 addition & 0 deletions lib/logfmt/encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Logfmt.Encoder do

iex> Logfmt.encode [foo: "bar baz", qux: true]
"foo=\"bar baz\" qux=true"

"""

@doc """
Expand Down
8 changes: 3 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Logfmt.MixProject do
use Mix.Project

@version "3.3.2"
@source_url "https://github.com/jclem/logfmt-elixir"
@version "3.3.2"

def project do
[
Expand Down Expand Up @@ -42,19 +42,17 @@ defmodule Logfmt.MixProject do

defp package do
[
contributors: ["Jonathan Clem <jotclem@gmail.com>"],
licenses: ["MIT"],
links: %{"GitHub" => @source_url},
maintainers: ["Jonathan Clem <jonathan@jclem.net>"],
files: ~w(mix.exs lib README.md LICENSE.md)
]
end

defp docs do
[
source_ref: "v#{@version}",
extras: ["LICENSE.md": [title: "License"], "README.md": [title: "Readme"]],
main: "readme",
extras: ["README.md": [title: "Readme"], "LICENSE.md": [title: "License"]]
source_ref: "v#{@version}"
]
end
end