<commit_before># Key=Value Log Formatter for Logrus

[![GoDoc](https://godoc.org/github.com/gwatts/kvlog?status.svg)](https://godoc.org/github.com/gwatts/kvlog)
[![Build Status](https://travis-ci.org/gwatts/kvlog.svg?branch=master)](https://travis-ci.org/gwatts/kvlog)

This package provides a text formatting type for Logrus.  It is similar to the
text formatter that comes with Logrus, but is focused on compatibility with
logging systems such as Splunk.

It provides a number of features

* All fields logged as key=value format (which Splunk automatically extracts).
* Fields keys are sorted into lexicographical order.
* Important/primary fields can be pinned to the start of each log entry
so they're easy to spot.
* Constant fields can be defined within the formatter.  For example, a build
commit hash can be included in every log entry automatically.
* All string types are wrapped in quotes automatically.
* Types can define their own marshaler for custom behaviour
* Compound types can return multiple key/value pairs by implementing a
Loggable interface.
* The calling function can optionally be included in every log entry.


Example usage:

```golang
log.SetFormatter(
    kvlog.New(
        // include the calling function name
        kvlog.IncludeCaller(), 

        // ensure action and status always appear first
        kvlog.WithPrimaryFields("action", "status")))

log.WithFields(log.Fields{
    "action":          "user_login",
    "status":          "ok",
    "username":        "joe_user",
    "email":           "<EMAIL>",
    "active_sessions": 4,
}).Info("User logged in")

// Output:
//  2017-01-02T12:00:00.000Z ll="info" srcfnc="Example" srcline=29 action="user_login" status="ok" active_sessions=4 email="<EMAIL>" username="joe_user" _msg="User logged in"
```
<commit_msg>Add README link to logrus<commit_after># Key=Value Log Formatter for Logrus

[![GoDoc](https://godoc.org/github.com/gwatts/kvlog?status.svg)](https://godoc.org/github.com/gwatts/kvlog)
[![Build Status](https://travis-ci.org/gwatts/kvlog.svg?branch=master)](https://travis-ci.org/gwatts/kvlog)

This package provides a text formatting type for [Logrus](https://github.com/sirupsen/logrus).  
It is similar to the text formatter that comes with Logrus, but is focused
on compatibility with logging systems such as Splunk.

It provides a number of features

* All fields logged as key=value format (which Splunk automatically extracts).
* Fields keys are sorted into lexicographical order.
* Important/primary fields can be pinned to the start of each log entry
so they're easy to spot.
* Constant fields can be defined within the formatter.  For example, a build
commit hash can be included in every log entry automatically.
* All string types are wrapped in quotes automatically.
* Types can define their own marshaler for custom behaviour
* Compound types can return multiple key/value pairs by implementing a
Loggable interface.
* The calling function can optionally be included in every log entry.


Example usage:

```golang
log.SetFormatter(
    kvlog.New(
        // include the calling function name
        kvlog.IncludeCaller(), 

        // ensure action and status always appear first
        kvlog.WithPrimaryFields("action", "status")))

log.WithFields(log.Fields{
    "action":          "user_login",
    "status":          "ok",
    "username":        "joe_user",
    "email":           "<EMAIL>",
    "active_sessions": 4,
}).Info("User logged in")

// Output:
//  2017-01-02T12:00:00.000Z ll="info" srcfnc="Example" srcline=29 action="user_login" status="ok" active_sessions=4 email="<EMAIL>" username="joe_user" _msg="User logged in"
```

{'fraction_non_alphanumeric': 0.10603990161246242, 'fraction_numerical': 0.01147854605083356, 'mean_word_length': 3.9392712550607287, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6729605', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1051, 'n_words': 382}