Comments (8)
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.
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.
Going to close the issue for now, please re-open it if the info above did not help.
from semantic_logger.
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.
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.
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.
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.
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)
- Semantic Logger removes keys from hash passed to loggers
- Support message and payload (v5 feature request) HOT 7
- Cannot use Sentry.init properly with sentry-ruby appender HOT 2
- Add support for New Relic log forwarding feature HOT 9
- Elasticsearch Specifying types in bulk requests is deprecated HOT 4
- Log level signal trap omits :fatal and :error levels HOT 2
- Suggestion: Change Loggable logger initialization from lazy to eager HOT 5
- RSpec test suite hangs intermittently unless `sync!` has been called HOT 1
- SemanticLogger.sync! is Not Thread-Safe
- Semantic Logger + Sidekiq 7 HOT 3
- Exception on `logger.error({ payload: '', foo: 'bar' })` (trying to log an arbitrary hash with `payload` key) HOT 1
- HTTP appender / Possible to write custom Headers HOT 1
- Segmentation fault in Formatters::Base for async appender HOT 2
- Improve CaptureLogEvents test logger HOT 1
- Error is raised when logging first occurs in a signal trap
- Base formatter time_format docs and behavior conflict, with no way to initialize it to nil in the ctor.
- Calling 'reopen' and Adding an Appender Creates 2 Logging Threads HOT 2
- Release Version 4.13 HOT 1
- Intermittent `NameError`/`LoadError` when loading Rails environment HOT 3
- HTTP appender batch: true
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from semantic_logger.