GithubHelp home page GithubHelp logo

isabella232 / logger_graylog_backend Goto Github PK

View Code? Open in Web Editor NEW

This project forked from esl/logger_graylog_backend

0.0 0.0 0.0 24 KB

Elixir's Logger backend for Graylog

License: Apache License 2.0

Elixir 100.00%

logger_graylog_backend's Introduction

LoggerGraylogBackend

This application provides a Logger backend for sendings log messages to Graylog. Currently only TCP transport is supported, and logs are always formatted in GELF format.

Installation

This library is not available on Hex (yet). You need to pull it directly from GitHub:

def deps do
  [{:logger_graylog_backend, github: "esl/logger_graylog_backend", tag: "v0.1.0"}, ...]
end

Usage

First you need to tell Logger to install this backend:

config :logger, backends: [LoggerGraylogBackend.Tcp]

and then configure the backend itself:

config :logger, LoggerGraylogBackend.Tcp,
  host: "your-graylog-hostname",
  port: 12201,
  # other options...

And that's it! Note that if the TCP backend won't be able to connect to the Graylog instance, it will try reconnecting indefinitely (with backoff).

Backend configuration

There are couple of configuration values you can provide to the backend:

  • :host (required) - host name or IP address (basically everything accepted by gen_tcp:connect/3) of the Graylog instance
  • :port (required) - port which the Graylog instance accepts TCP connections on
  • :level (optional, default: info) - the log level (:debug, :info, :warn or :error)

Formatter

Logs sent by the backend are always in GELF 1.1 format. The following fields are included in the payload by default:

  • "version" - always has value "1.1"
  • "host" - hostname retrieved using inet:gethostname/0 (might be overriden)
  • "timestamp" - the log timestamp in seconds and milliseconds as fractional part (can be excluded)
  • "short_message" - the log message
  • "level" - the log severity formatted as a number as in syslog

In addition, all metadata provided by Logger will be included as additional fields (thus prefixed with _). What metadata is included in the message is also configurable.

Conifugration

You can configure the formatter using the following options:

  • :include_timestamp (default: true) - tells the formatted to include the "timestamp" field. Note that Graylog generates the timestamp itself if the incoming log message doesn't have it
  • :override_host (default: false)- if set, the "host" field in the GELF log will have the configured value. Might be set to false to make the formatter use system hostname
  • :metadata (default: :all) - filters what metadata will be included in the message, possible values are:
    • :all - all metadata
    • list of atoms - only metadata with keys present in the provided list
    • {module, function} - a module/function pair which will be called when generatin the GELF message. The function should take four arguments (log level, log message, timestamp and all metadata) and return the metadata which will be included in the message

Example configuration

config :logger, backends: [LoggerGraylogBackend.Tcp]

config :logger, LoggerGraylogBackend.Tcp,
  host: "example.com",
  port: 12201,
  level: :warn,
  include_timestamp: false,
  override_host: "my-app",
  metadata: [:application, :file, :line]

License

Copyright 2018 Erlang Solutions

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

logger_graylog_backend's People

Contributors

arkgil avatar rranelli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.