{"action":"created","issue":{"url":"https://api.github.com/repos/reidmorrison/semantic_logger/issues/13","labels_url":"https://api.github.com/repos/reidmorrison/semantic_logger/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/reidmorrison/semantic_logger/issues/13/comments","events_url":"https://api.github.com/repos/reidmorrison/semantic_logger/issues/13/events","html_url":"https://github.com/reidmorrison/semantic_logger/issues/13","id":96411541,"number":13,"title":"Rack::CommonLogger","user":{"login":"amedeiros","id":1771494,"avatar_url":"https://avatars.githubusercontent.com/u/1771494?v=3","gravatar_id":"","url":"https://api.github.com/users/amedeiros","html_url":"https://github.com/amedeiros","followers_url":"https://api.github.com/users/amedeiros/followers","following_url":"https://api.github.com/users/amedeiros/following{/other_user}","gists_url":"https://api.github.com/users/amedeiros/gists{/gist_id}","starred_url":"https://api.github.com/users/amedeiros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amedeiros/subscriptions","organizations_url":"https://api.github.com/users/amedeiros/orgs","repos_url":"https://api.github.com/users/amedeiros/repos","events_url":"https://api.github.com/users/amedeiros/events{/privacy}","received_events_url":"https://api.github.com/users/amedeiros/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-21T20:40:34Z","updated_at":"2015-07-23T01:58:27Z","closed_at":null,"body":"Im working on a small sinatra application I wanted to switch out the Rack::CommonLogger with semantic logger so sinatra will log with semantic_logger. This does not seem possible, and I think its just semantic_logger missing some things to make it compatible but wanted to see if you could confirm\r\n\r\nExample:\r\nRequired gems: sinatra, sinatra-contrib, semantic_logger\r\n\r\nIn this example the log statement in the main end point logs just fine. However, nothing from Rack::CommonLogger is making it into the log.\r\n```ruby\r\nrequire 'sinatra'\r\nrequire 'sinatra/custom_logger'\r\nrequire 'semantic_logger'\r\n\r\nconfigure do\r\n  register Sinatra::CustomLogger\r\n  SemanticLogger.default_level = :info\r\n  SemanticLogger.add_appender(\"#{settings.root}/log/#{settings.environment}.log\", &SemanticLogger::Appender::Base.colorized_formatter)\r\n  logger = SemanticLogger['TestLogger']\r\n  set :raise_errors, true\r\n  set :logger, logger\r\n  use Rack::CommonLogger, logger\r\nend\r\n\r\nget '/' do\r\n  # This makes it into the log file. But nothing from Rack::CommonLogger\r\n  logger.warn(\"Test\")\r\n  'Logger testing'\r\nend\r\n```\r\n\r\nIn this example the log statement and the Rack::CommonLogger logs are making it into the log file which leads me to believe that semantic_logger is not compatible with Rack::CommonLogger\r\n\r\n```ruby\r\nrequire 'sinatra'\r\nrequire 'sinatra/custom_logger'\r\nrequire 'logger'\r\n\r\nconfigure do\r\n  register Sinatra::CustomLogger\r\n  logger = Logger.new(\"#{settings.root}/log/#{settings.environment}.log\")\r\n  set :raise_errors, true\r\n  set :logger, logger\r\n  use Rack::CommonLogger, logger\r\nend\r\n\r\nget '/' do\r\n  # This makes it into the log file and also from Rack::CommonLogger\r\n  logger.warn(\"Test\")\r\n  'Logger testing'\r\nend\r\n```\r\n\r\nThe only difference between the two scenarios is one uses the logger class from ruby which is compatible with Rack::CommonLogger and the other is using SemanticLogger which does not seem compatible with Rack::CommonLogger.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/reidmorrison/semantic_logger/issues/comments/123929267","html_url":"https://github.com/reidmorrison/semantic_logger/issues/13#issuecomment-123929267","issue_url":"https://api.github.com/repos/reidmorrison/semantic_logger/issues/13","id":123929267,"user":{"login":"reidmorrison","id":146852,"avatar_url":"https://avatars.githubusercontent.com/u/146852?v=3","gravatar_id":"","url":"https://api.github.com/users/reidmorrison","html_url":"https://github.com/reidmorrison","followers_url":"https://api.github.com/users/reidmorrison/followers","following_url":"https://api.github.com/users/reidmorrison/following{/other_user}","gists_url":"https://api.github.com/users/reidmorrison/gists{/gist_id}","starred_url":"https://api.github.com/users/reidmorrison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reidmorrison/subscriptions","organizations_url":"https://api.github.com/users/reidmorrison/orgs","repos_url":"https://api.github.com/users/reidmorrison/repos","events_url":"https://api.github.com/users/reidmorrison/events{/privacy}","received_events_url":"https://api.github.com/users/reidmorrison/received_events","type":"User","site_admin":false},"created_at":"2015-07-23T01:58:27Z","updated_at":"2015-07-23T01:58:27Z","body":"In the second scenario I get the following error:\r\n```shell\r\nPuma 2.8.2 starting...\r\n* Min threads: 0, max threads: 16\r\n* Environment: development\r\n* Listening on tcp://localhost:4567\r\n== Sinatra (v1.4.6) has taken the stage on 4567 for development with backup from Puma\r\n2015-07-22 21:55:01 -0400: Read error: #<NoMethodError: undefined method `write' for #<Logger:0x007fe3c13265c0>>\r\n/Users/rmorrison/.rvm/gems/ruby-2.2.2@connect/gems/rack-1.5.5/lib/rack/commonlogger.rb:46:in `log'\r\n```\r\n\r\nWith 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:\r\n```ruby\r\nrequire 'sinatra'\r\nrequire 'sinatra/custom_logger'\r\nrequire 'semantic_logger'\r\n\r\nconfigure do\r\n  register Sinatra::CustomLogger\r\n  SemanticLogger.default_level = :info\r\n  SemanticLogger.add_appender(\"test1.log\", &SemanticLogger::Appender::Base.colorized_formatter)\r\n  logger = SemanticLogger['TestLogger']\r\n\r\n  # Send write calls to #info\r\n  logger.instance_eval do\r\n    def write(str)\r\n      info(str)\r\n    end\r\n  end\r\n\r\n  set :raise_errors, true\r\n  set :logger, logger\r\n  use Rack::CommonLogger, logger\r\nend\r\n\r\nget '/' do\r\n  # This makes it into the log file. But nothing from Rack::CommonLogger\r\n  logger.warn(\"Test\")\r\n  'Logger testing'\r\nend\r\n```"}}