luckyframework / dexter

A logger with maximum customizability and surgical precision
MIT License
21 stars 4 forks source link

Logger is formatter method is causing code to not compile when other libs use logger #2

Closed Xosmond closed 5 years ago

Xosmond commented 5 years ago

The method formatter is causing other libraries to not compile: https://github.com/luckyframework/dexter/blob/master/src/dexter/logger.cr#L53

# :nodoc:
  def formatter=(value) : Void
    {% raise "Use log_formatter= instead" %}
  end

So even when using ::Logger like:

    def initialize(@io : IO = STDOUT)
      @logger = ::Logger.new(@io)
      @logger.level = ::Logger::DEBUG
      @logger.progname = "crest"
      @logger.formatter = default_formatter
      @filters = [] of Array(String | Regex)
    end

    abstract def request(request : Crest::Request) : String
    abstract def response(response : Crest::Response) : String

    def default_formatter
      ::Logger::Formatter.new do |_, datetime, progname, message, io|
        io << progname
        io << " | " << datetime.to_s("%F %T")
        io << " " << message
      end
    end

It get's the following error:

  in lib/crest/src/crest/logger.cr:19: undefined method 'log_formatter=' for Logger (compile-time type is Logger+)

      @logger.log_formatter = Dexter::Formatters::JsonLogFormatter