Giter Club home page Giter Club logo

logflare_logger_backend's Introduction

LogflareLogger

An Elixir Logger backend for Logflare. Streams logs to the Logflare.app API.

Configuration

Get your api_key and create a source at logflare.app

You will need a Logflare source source_id which you can copy from your dashboard after you create a one.

config :logger,
  level: :info, # or other Logger level
  backends: [LogflareLogger.HttpBackend]

config :logflare_logger_backend,
  url: "https://api.logflare.app", # https://api.logflare.app is configured by default and you can set your own url
  level: :info, # Default LogflareLogger level is :info. Note that log messages are filtered by the :logger application first
  api_key: "...", # your Logflare API key, found on your dashboard
  source_id: "...", # the Logflare source UUID, found  on your Logflare dashboard
  flush_interval: 1_000, # minimum time in ms before a log batch is sent
  max_batch_size: 50, # maximum number of events before a log batch is sent
  metadata: :all # optionally you can drop keys if they exist with `metadata: [drop: [:list, :keys, :to, :drop]]`

Alternatively, you can configure these options in your system environment. Prefix the above option names with LOGFLARE_.

export LOGFLARE_URL="https://api.logflare.app"
export LOGFLARE_API_KEY="..."
export LOGFLARE_SOURCE_ID="..."

Usage

After configuring LogflareLogger in config.exs, use Logger.info, Logger.error, ... functions to send log events to Logflare app.

Usage with context

LogflareLogger.context function signatures follows the one of Logger.metadata with slight modifications to parameters and return values.

# Merges map or keyword with existing context, will overwrite values.
LogflareLogger.context(%{user: %{id: 3735928559}})
LogflareLogger.context(user: %{id: 3735928559})

# Get all context entries or a value for a specific key
LogflareLogger.context(:user)
LogflareLogger.context()

# Deletes all context entries or specific context key/value
LogflareLogger.context(user: nil)
LogflareLogger.reset_context()

Current limitations

Logflare log event BigQuery table schema is auto-generated per source. If you send a log with Logger.info("first", user: %{id: 1}), Logflare will generate a metadata field of type integer. If in the future, you'll send a log event to the same source using Logger.info("first", user: %{id: "d9c2feff-d38a-4671-8de4-a1e7f7dd7e3c"1}), the log with a binary id will be rejected.

LogflareLogger log payloads sent to Logflare API are encoded using BERT.

At this moment LogflareLogger doesn't support full one-to-one logging of Elixir types and applies the following conversions:

  • atoms converted to strings
  • charlists are converted to strings
  • tuples converted to arrays
  • keyword lists converted to maps
  • structs converted to maps
  • NaiveDateTime and DateTime are converted using the String.Chars protocol
  • pids are converted to strings

LogflareLogger doesn't support:

  • non-binary messages, e.g. Logger.info(%{user_count: 1337})

Exceptions

LogflareLogger automatically logs all exceptions and formats stacktraces.

Troubleshooting

Run mix logflare_logger.verify_config to test your config.

Email [email protected] for help!

Installation

If available in Hex, the package can be installed by adding logflare_logger_backend to your list of dependencies in mix.exs:

def deps do
  [
    {:logflare_logger_backend, "~> 0.11.4"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/logflare_logger_backend.

logflare_logger_backend's People

Contributors

ontofractal avatar chasers avatar dependabot-preview[bot] avatar dependabot[bot] avatar filipecabaco avatar josevalim avatar ziinc avatar darksheik avatar dylan-aidkr avatar jechol avatar mveytsman avatar fantypants avatar hauleth 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.