Giter VIP home page Giter VIP logo

hut's Introduction

Travis Hex.pm Version Hex.pm License Build Tool

NOTE: Since both Erlang and Elixir provide pluggable logging facilities out of the box for a while now, the benefit of using hut has been reduced. One may still use it, however it doesn't provide much benefit nowadays.

Overview

hut is a minimal library for Erlang libraries and small applications to stay agnostic to the logging framework in use. Its purpose is to allow the developers of umbrella applications to use their logging framework of choice and ensure that dependency stick to that choice as well.

Origin

The idea for hut came out of a discussion about exometer_core's logging facilities.

Usage

  1. Include hut as a dependency in your toolchain.
  2. Include hut in your .erl files via -include_lib(hut/include/hut.hrl)
  3. Log with
  • ?log(Level, Msg) to log the given message
  • ?log(Level, Fmt, Args) to format the given message with the arguments using io_lib:format/2
  • ?log(Level, Fmt, Args, Opts) to pass additional options to the logging backend in use
  • ?slog(Level, #{key1 => Value1, ...}) structured log message
  • ?slog(Level, Data :: map(), Metadata :: map()) structured log message with custom metadata
  • ?set_process_metadata(Metadata :: map()) add custom metadata to the process
  1. Compile and pass the appropriate macro to the compiler to enable a certain backend as described next.
  2. Ensure that the application hut is started as part of your system.

Supported Logging Backends

  • SASL error_logger as the default (on OTP20 and older)
  • logger as the default on OTP21+
  • io:format/2 via -DHUT_IOFORMAT
  • no-op logging via -DHUT_NOOP
  • Lager via -DHUT_LAGER (you may optionally specify a different log message sink by additionally defining -DHUT_LAGER_SINK mysinkname; the default message sink is lager)
  • custom callback module via -DHUT_CUSTOM -DHUT_CUSTOM_CB mycbmod (the module must provide the function log(Level, Fmt, Args, Opts)

Log Level Gates

hut provides a simple mechanisms to drop log messages depending on the enabled log level. The functionality is similar to how Lager works with log levels.

The current log level (default is info) can be set through the application variable level:

erl -hut level debug

All log messages with levels below the current log level will be dropped.

The gating mechanism can be disabled through the application variable use_log_level_gate:

erl -hut use_log_level_gate false

NOTE: The gating mechanism is not supported for the Lager backend, since Lager itself provides a similar functionality which you should rely on when using Lager.

Examples

Refer to the respective Makefile in each example for details.

  • examples/basic shows the use of all backends from an Erlang library
  • examples/elixir shows how to use a hut-enabled Erlang library within an Elixir application
  • examples/rebar3 shows how to use hut in a rebar3 project

hut's People

Contributors

jadeallenx avatar k32 avatar mmmries avatar okeuday avatar tolbrino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hut's Issues

hut on hex.pm has not build tool metadata

Following a quick discussion on IRC it appeared that hut don't have the buildtool metadat set which prevents people using rebar3 to use it:

 rebar3 hex search hut  return nothing but https://hex.pm/packages?search=hut&sort=downloads
20:33 return a version

20:38 E<ericmj> 
benoitc: i think rebar3 only searches for packages that use rebar3
20:39 and hut hasn’t set any build tool

Can you eventually resend a new version on hex?

HUT_CUSTOM should not try to manage log level

Currently HUT_CUSTOM backend tries to manage log levels via ?maybe_log macro and hut application environment. I think it may be reasonable to make behavior of HUT_CUSTOM dumber and let the callback manage log levels and what not. Real world example: suppose we want to integrate an application using hut into an old system with its own custom logging framework. It already has the necessary configuration, there's no need to duplicate it in hut.

I can do the necessary changes either by introducing a new hut backend or just fixing the existing one (and breaking the BC).

Configuring hut with standard Erlang application environment

I'm using exometer from an Elixir app and log messages are being repeated twice. I guess I need to configure hut to report to lager, which is configured to log through logger.

The normal way to configure an application in Elixir is though Erlang's application environment. Is it possible to configure hut this way?

Rebar2 incompatibility in OTP24

Hi @tolbrino, Hope you're safe and well.

bamboo_smtp package is already dependent on [email protected] and on the other hand OTP24+ no longer supports rebar2.

Sample Warning

dependency :hut is using Rebar 2, which is no longer maintained and no longer works in recent Erlang/OTP versions. Remove the :manager option or set it to :rebar3 instead

What's your thought on this and is it possible to get rid of this warning by suggested message?

Publish Hex Package

Hi. I'm working on jlouis/turtle#8 trying to make it available as a hex package. hut is a transitive dependency of that project and so I would also like to make this project available as a hex package.

Is this something that the maintainers of this project are interested in?
You could publish it by adding a mix.exs file or by using the rebar3 plugin for hex publishing. I'd be happy to help out with a PR for either one of those solutions if you are interested. Thanks for all your work making great open source tools ❤️ 😍 🎉

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.