Git Product home page Git Product logo

jsonformat's Introduction

jsonformat

A custom formatter for Erlang OTP logger that outputs JSON using jsx

Getting Started

This project should be added as a dependency to your project

Prerequisites

sys.config:

[ { kernel
  , [ { logger
      ,[ { handler
         , default
         , logger_std_h
         , #{formatter => {jsonformat, #{new_line => true}}}
         }
       ] }
    , {logger_level, info}
   ] }
].

shell:

> logger:info(#{a => b}).
{"a":"b","gl":"<0.178.0>","level":"info","pid":"<0.182.0>","report_cb":"fun logger:format_otp_report/1","time":1585902924341139}ok

Configuration Options

To print each json object to a new line, set new_line to true:

#{formatter => {jsonformat, #{ new_line => true }}}

To specify which kind of line ending to use, set new_line_type to one of nl, crlf, cr, unix, windows or macos9. These correspond to:

  • nl or unix means \n, ASCII character 0x0A
  • crlf or windows means \r\n, ASCII characters 0x0D 0x0A
  • cr or macos9 means \r, ASCII character 0x0D

The default line ending if none is specified is nl.

#{formatter => {jsonformat, #{ new_line => true, new_line_type => crlf }}}

To control what is being included in the log object from the metadata, there are two ways. One can opt-out from fields. Default opts out is [report_cb].

#{ meta_without => [report_cb, gl, file, domain] }

Or for very detailed control there is instead opt-in.

#{ meta_with => [time, mfa, line, user_key, client_key] }

To rename keys in the resulting json object, provide a key_mapping. For example, to rename the time and level keys to timestamp and lvl respectively, use:

#{formatter => {jsonformat, #{ key_mapping => #{ time => timestamp
                                               , level => lvl }}}}

To format values in the resulting json object, provide a map of format_funs. For example, to format the value associated with the time key, use:

#{formatter => {jsonformat, #{ format_funs => #{ time => fun(T) -> ... end }}}

Note that key_mappings are applied before format_funs.

Built in formatters

fun jsonformat:system_time_to_iso8601/1

Will take a logger:timestamp() and print it in the format of yyyy-mm-ddTHH:MM:SSZ

Running the tests

$ rebar3 eunit

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Commit message convention

We use Conventional Commits.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE file for details

jsonformat's People

Contributors

moritzploss-k avatar maxno-kivra avatar bipthelin avatar chsukivra avatar andreashasse avatar kbip avatar cdyb-kivra avatar

Stargazers

 avatar Mirko Kovačević avatar Massimo Cesaro avatar Nikolaus Schlemm avatar Sanhaji Omar avatar Alex Valiushko avatar Mikael Lixenstrand avatar Hoang Phan avatar V avatar Dmitry Sviderskiy avatar Artem Teslenko avatar  avatar Roman Pushkov avatar

Watchers

James Cloos avatar Kondal Rao Komaragiri avatar  avatar  avatar Tony Träskelin avatar  avatar Kevin Whittaker 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.