Giter Site home page Giter Site logo

exlager's Introduction

ExLager

This package implements a simple wrapper over https://github.com/basho/lager.

It embeds logging calls to ExLager into a module if currently configured logging level is less or equal than severity of a call. Therefore it doesn't have any negative impact on performance of a production system when you configure error level even if you have tons of debug messages.

Information about location of a call (module, function, line, pid) is properly passed to lager for your convenience so you can easily find the source of a message. In this aspect using ExLager is equal to using parse transform shipped with basho lager.

Since ExLager depends on macro implemented in Lager module you have to require it. Then you call one of logging methods on Lager module. There are seven logging methods in order of severity:

  • debug
  • info
  • notice
  • warning
  • error
  • critical
  • alert
  • emergency

Examples:

defmodule Test do
  require Lager
  def debug do
    Lager.debug "Hi debug"
  end
  def info do
    Lager.info "Hi error"
  end
  def notice do
    Lager.notice "Hi notice"
  end
  def warning do
    Lager.warning "Hi warning"
  end
  def error do
    Lager.error "Hi error"
  end
  def critical do
    Lager.critical "Hi critical"
  end
  def alert do
    Lager.alert "Hi alert"
  end
  def emergency do
    Lager.emergency "Hi emergency"
  end
  def test do
    debug
    info
    notice
    warning
    error
    critical
    alert
    emergency
  end
end

Application.start :exlager
Test.test

Configuration

It is possible to configure truncation size and compile time log level. Being a simple wrapper ExLager doesn't attempt to configure underlying Lager. You would need to configure it yourself see to ensure that:

  • lager_truncation_size >= compile_truncation_size
  • lager severity level >= compile_log_level
  • appropriate handlers are configured

Configuration of ExLager can be done by calling helper functions of Lager from your build system as follows:

iex(1)> Lager.compile_log_level(:info)
true
iex(2)> Lager.compile_truncation_size(512)
true

If you cannot call those function you can set compiler options:

iex(3)> Code.compiler_options exlager_level: :debug
ok
iex(4)> Code.compiler_options exlager_truncation_size: 512
ok

If you are mix user you could specify level and truncation_size in config/config.#{Mix.env}.exs as follows:

    use Mix.Config

    config :exlager,
      level: :debug,
      truncation_size: 8096

Multiple Sink Support

As of Lager 3.x, you can configure multiple sinks to provide different behavior for different streams of logs. To use a different sink, prepend the name to the logging calls above. For example, to use the magic_lager_event sink, you can do the following:

Lager.info :magic, "magic event"

exlager's People

Contributors

dmilith avatar edgurgel avatar eraserewind avatar ericmj avatar gamepoet avatar jparise avatar jsvisa avatar jvantuyl avatar khia avatar liveforeverx avatar parroty avatar pguillory avatar reachfh 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  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  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

exlager's Issues

exlager_level as an atom

I'd be great if it was possible to specify compiler's option exlager_level as :debug and not 7. Thoughts?

Exlager does not have a license

Does it use the same Apache license as Lager itself? If so it would be great to have a copy of the license file in the repository.

Lager setting should be mentioned in README

Hello,
I consider Exlager really nice but (if I didn't miss something) in the README there is not mentioned one crucial moment - underlying Lager has it's own default setting which is not affected by Exlager settings. It took me some time to realize this...

For instance if you set
elixirc_options: [exlager_level: :debug, exlager_truncation_size: 8096]
you still get no debug messages in the console because lager has default
{handlers, [{lager_console_backend, info}, ...
(see https://github.com/basho/lager/blob/master/src/lager.app.src )

IMHO there should be some warning in the README that you must override the default with app.config, explicitly use lager:set_loglevel/2 or such... and ideally Exlager should have some way to set Lager's options.

P.S. thank you very much for your work on Exlager!

Couldn't make it work as is

I just tried exlager out and it seems that unless you start lager app at least once before the compilation pass, it would fail with this error: (undefined module :"lager_mochiglobal:loglevel").

I presume you didn't catch the problem because you already had lager started at least once. I didn't spend much time on this one so I can't actually 100% confirm that this is the reason for the above error. However, this is a huge deal breaker because, well, it renders exlager unusable.

Any thoughts on how to fix this?

Does not seem to be able to configure lager

Hi,

I'm trying to use exlager. Everthing looks ok, until I try to configure lager.

here in my mix file

def project do
   [ app: ..., elixirc_options: options(Mix.env)]
end

def options(:test) do
  [exlager_level: :emergency]
end

but when I run the tests:

11:18:56.893 [info] Application lager started on node nonode@nohost
11:18:56.893 [info] Application exlager started on node nonode@nohost
11:18:56.893 [info] Application re_inspector_backend started on node nonode@nohost
11:18:56.914 [info] Application ex_unit started on node nonode@nohost

I'm using Elizir 0.12.4 & exlager SHA1 779a753

David

Any intent on publishing to hex.pm?

Hi! I don't see exlager on hex.pm. Any plans on publishing it there? If not, would you mind if I publish it (as a contributor on this repo, or from a fork)?

Cheers,
Michael

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.