Git Product home page Git Product logo

Comments (8)

reidmorrison avatar reidmorrison commented on June 14, 2024

In the second scenario I get the following error:

Puma 2.8.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567
== Sinatra (v1.4.6) has taken the stage on 4567 for development with backup from Puma
2015-07-22 21:55:01 -0400: Read error: #<NoMethodError: undefined method `write' for #<Logger:0x007fe3c13265c0>>
/Users/rmorrison/.rvm/gems/ruby-2.2.2@connect/gems/rack-1.5.5/lib/rack/commonlogger.rb:46:in `log'

With the first scenario I get a similar error. It appears we just need to map #write to for example #info. The following does the trick:

require 'sinatra'
require 'sinatra/custom_logger'
require 'semantic_logger'

configure do
  register Sinatra::CustomLogger
  SemanticLogger.default_level = :info
  SemanticLogger.add_appender("test1.log", &SemanticLogger::Appender::Base.colorized_formatter)
  logger = SemanticLogger['TestLogger']

  # Send write calls to #info
  logger.instance_eval do
    def write(str)
      info(str)
    end
  end

  set :raise_errors, true
  set :logger, logger
  use Rack::CommonLogger, logger
end

get '/' do
  # This makes it into the log file. But nothing from Rack::CommonLogger
  logger.warn("Test")
  'Logger testing'
end

from semantic_logger.

amedeiros avatar amedeiros commented on June 14, 2024

Ok thank you I will give that a try. I just really want to be able to use your logger its just much cleaner output and Im familiar with it.

from semantic_logger.

reidmorrison avatar reidmorrison commented on June 14, 2024

Going to close the issue for now, please re-open it if the info above did not help.

from semantic_logger.

deepak07 avatar deepak07 commented on June 14, 2024

Hi @reidmorrison ,
I am facing similar issue. When I try to log in development environment, everything is working fine. But when I started running the application in QA environment nothing gets logged in the file. But when switched to Rack::CommonLogger requests are getting logged.

  • I am using passenger using nginx to run the application

Anything that need to be done?

from semantic_logger.

reidmorrison avatar reidmorrison commented on June 14, 2024

Aside from doing the above, since you are using a forking framework and not using Rails Semantic Logger you also need add a callback to re-open log files after forking: https://rocketjob.github.io/semantic_logger/forking.html

from semantic_logger.

reidmorrison avatar reidmorrison commented on June 14, 2024

There is an opportunity for someone that uses Sinatra to create a sinatra_semantic_logger gem that does for Sinatra what the rails_semantic_logger gem does for Rails.

from semantic_logger.

deepak07 avatar deepak07 commented on June 14, 2024

I will make an effort to put out sinatra_semantic_logger . Let me see if I can come up with a solution.

from semantic_logger.

deepak07 avatar deepak07 commented on June 14, 2024

The issue was with forking. Adding semantic logger reload code on forking fixed it. Now logs are appearing. Thanks @reidmorrison for pointing it out.

from semantic_logger.

Related Issues (20)

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.