All Projects → Nebo15 → Logger_json

Nebo15 / Logger_json

Licence: mit
JSON console backend for Elixir Logger.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Logger json

Log4rs
A highly configurable logging framework for Rust
Stars: ✭ 483 (+347.22%)
Mutual labels:  json, logging, log
Co
Art of C++. Flag, logging, unit-test, json, go-style coroutine and more.
Stars: ✭ 2,264 (+1996.3%)
Mutual labels:  json, logging, log
Nim Morelogging
Logging library for Nim
Stars: ✭ 29 (-73.15%)
Mutual labels:  logging, log
Dotlog
Simple and easy go log framework
Stars: ✭ 30 (-72.22%)
Mutual labels:  logging, log
Log4j2 Ttl Thread Context Map
🌳 Log4j2 TTL ThreadContextMap, Log4j2 extension integrated TransmittableThreadLocal to MDC
Stars: ✭ 41 (-62.04%)
Mutual labels:  logging, log
Yii2 Slack Log
Pretty Slack log target for Yii 2
Stars: ✭ 24 (-77.78%)
Mutual labels:  logging, log
Gollum
An n:m message multiplexer written in Go
Stars: ✭ 883 (+717.59%)
Mutual labels:  logging, log
Fliplog
fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, tracking, presets, & more...
Stars: ✭ 41 (-62.04%)
Mutual labels:  logging, log
Electron Log
Just a simple logging module for your Electron application
Stars: ✭ 765 (+608.33%)
Mutual labels:  logging, log
Yii2 Psr Log Target
Yii 2.0 log target that is able to write messages to PSR-3 compatible logger
Stars: ✭ 58 (-46.3%)
Mutual labels:  logging, log
Plog
Portable, simple and extensible C++ logging library
Stars: ✭ 1,061 (+882.41%)
Mutual labels:  logging, log
Android Filelogger
A general-purpose logging library with built-in support to save logs to file efficiently.
Stars: ✭ 70 (-35.19%)
Mutual labels:  logging, log
Illuminati
This is a Platform that collects all the data accuring in your Application and shows the data in real time by using Kibana or other tools.
Stars: ✭ 106 (-1.85%)
Mutual labels:  logging, log
Yii2 Telegram Log
Telegram log target for Yii 2
Stars: ✭ 24 (-77.78%)
Mutual labels:  logging, log
Adenium
Adenium Normalizer
Stars: ✭ 29 (-73.15%)
Mutual labels:  logging, log
Logging Helpers
Basic template helpers for printing messages out to the console. Useful for debugging context in templates. Should work with any template engine.
Stars: ✭ 5 (-95.37%)
Mutual labels:  logging, log
Loglevelnext
A modern logging library for Node.js that provides log level mapping to the console
Stars: ✭ 33 (-69.44%)
Mutual labels:  logging, log
Laravel Log To Db
Custom Laravel and Lumen 5.6+ Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel/Monolog native logging functionality.
Stars: ✭ 76 (-29.63%)
Mutual labels:  logging, log
Poco
The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
Stars: ✭ 5,762 (+5235.19%)
Mutual labels:  json, logging
Dozzle
Realtime log viewer for docker containers.
Stars: ✭ 684 (+533.33%)
Mutual labels:  logging, log

LoggerJSON

Hex.pm Downloads Latest Version License Build Status Coverage Status SourceLevel

JSON console back-end for Elixir Logger.

It can be used as drop-in replacement for default :console Logger back-end in cases where you use use Google Cloud Logger or other JSON-based log collectors.

Minimum supported Erlang/OTP version is 20.

Motivation

We deploy our applications as dockerized containers in Google Container Engine (Kubernetes cluster), in this case all your logs will go to stdout and log solution on top of Kubernetes should collect and persist it elsewhere.

In GKE it is persisted in Google Cloud Logger, but traditional single Logger output may contain newlines for a single log line, and GCL counts each new line as separate log entry, this making it hard to search over it.

This backend makes sure that there is only one line per log record and adds additional integration niceness, like LogEntry format support.

After adding this back-end you may also be interested in redirecting otp and sasl reports to Logger (see "Error Logger configuration" section).

Log Format

LoggerJSON provides two JSON formatters out of the box (see below for implementing your own custom formatter).

The LoggerJSON.Formatters.BasicLogger formatter provides a generic JSON formatted message with no vendor specific entries in the payload. A sample log entry from LoggerJSON.Formatters.BasicLogger looks like the following:

{
  "time": "2020-04-02T11:59:06.710Z",
  "severity": "debug",
  "message": "hello",
  "metadata": {
    "user_id": 13
  }
}

The other formatter that comes with LoggerJSON is LoggerJSON.Formatters.GoogleCloudLogger and generates JSON that is compatible with the Google Cloud Logger LogEntry format:

{
  "message":"hello",
  "logging.googleapis.com/sourceLocation":{
    "file":"/os/logger_json/test/unit/logger_json_test.exs",
    "function":"Elixir.LoggerJSONGoogleTest.test metadata can be configured/1",
    "line":71
  },
  "severity":"DEBUG",
  "time":"2018-10-19T01:10:49.582Z",
  "user_id":13
}

Log entry in Google Cloud Logger would looks something like this:

{
  "httpRequest":{
    "latency":"0.350s",
    "remoteIp":"::ffff:10.142.0.2",
    "requestMethod":"GET",
    "requestPath":"/",
    "requestUrl":"http://10.16.0.70/",
    "status":200,
    "userAgent":"kube-probe/1.10+"
  },
  "insertId":"1g64u74fgmqqft",
  "jsonPayload":{
    "message":"",
    "phoenix":{
      "action":"index",
      "controller":"Elixir.MyApp.Web.PageController",
    },
    "request_id":"2lfbl1r3m81c40e5v40004c2",
    "vm":{
      "hostname":"myapp-web-66979fc-vbk4q",
      "pid":1,
    }
  },
  "logName":"projects/hammer-staging/logs/stdout",
  "metadata":{
    "systemLabels":{},
    "userLabels":{}
  },
  "operation":{
    "id":"2lfbl1r3m81c40e5v40004c2"
  },
  "receiveTimestamp":"2018-10-18T14:33:35.515253723Z",
  "resource":{},
  "severity":"INFO",
  "sourceLocation":{
    "file":"iex",
    "function":"Elixir.LoggerJSON.Plug.call/2",
    "line":"36"
  },
  "timestamp":"2018-10-18T14:33:33.263Z"
}

You can change this structure by implementing LoggerJSON.Formatter behaviour and passing module name to :formatter config option. Example module can be found in LoggerJSON.Formatters.GoogleCloudLogger.

config :logger_json, :backend,
  formatter: MyFormatterImplementation

Installation

It's available on Hex, the package can be installed as:

  1. Add :logger_json to your list of dependencies in mix.exs:
def deps do
  [{:logger_json, "~> 4.0"}]
end
  1. Set configuration in your config/config.exs:
config :logger_json, :backend,
  metadata: :all

Some integrations (for eg. Plug) uses metadata to log request and response parameters. You can reduce log size by replacing :all (which means log all) with a list of the ones that you actually need.

  1. Replace default Logger :console back-end with LoggerJSON:
config :logger,
  backends: [LoggerJSON]
  1. Optionally. Log requests and responses by replacing a Plug.Logger in your endpoint with a:
plug LoggerJSON.Plug
  1. Optionally. Use Ecto telemetry for additional metadata:

Attach telemetry handler for Ecto events in start/2 function in application.ex

:ok =
  :telemetry.attach(
    "logger-json-ecto",
    [:my_app, :repo, :query],
    &LoggerJSON.Ecto.telemetry_logging_handler/4,
    :debug
  )

Prevent duplicate logging of events, by setting log configuration option to false

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  log: false

Dynamic configuration

For dynamically configuring the endpoint, such as loading data from environment variables or configuration files, LoggerJSON provides an :on_init option that allows developers to set a module, function and list of arguments that is invoked when the endpoint starts.

config :logger_json, :backend,
  on_init: {YourApp.Logger, :load_from_system_env, []}

Encoders support

You can replace default Jason encoder with other module that supports encode_to_iodata!/1 function and enconding fragments.

Documentation

The docs can be found at https://hexdocs.pm/logger_json

Thanks

Many source code has been taken from original Elixir Logger :console back-end source code, so I want to thank all it's authors and contributors.

Part of LoggerJSON.Plug module have origins from plug_logger_json by @bleacherreport, originally licensed under Apache License 2.0. Part of LoggerJSON.PlugTest are from Elixir's Plug licensed under Apache 2.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].