RocketMQLog:WARN Please initialize the logger system properly? - rocketmq

run the Producer , show this:
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.InternalThreadLocalMap). RocketMQLog:WARN Please initialize the logger system properly.
How to configure ?

will be fixed in RocketMQ4.9.4, or you fix by this pr
https://github.com/apache/rocketmq/pull/4001

Related

Ruby logger scope

I am trying to create a simple logging solution for my program using ruby's built in logger function. At the moment, what I have is the initialization for the logger like this:
class Setup
def initialize
logger = Logger.new(logfile.log)
logger.level = 'DEBUG'
logger.datetime_format = '%Y-%m-%d %H:%M:%S'
And then when I try to call to the logger within other functions in the same class with:
logger.info('testlog')
I get an error saying:
undefined local variable or method 'logger'
How should I access the logger from outside the local scope of the method it is defined in?
Thanks in advance.
logger is a local variable, which is only visible in the area where it was defined. Rename it to #logger to make it be an instance variable which is stored inside the object and can be used from any of the object's methods.

Keep separate Log4J log files in each URL

I need to keep separate log4j log files in a separate folder.Those log files should be separated for each URL.My project is Spring MVC project.
For example,
www.xyz.com/test/url1
www.xyz.com/test/url2
www.xyz.com/test/url3
How can I configure my log4j?
Is there a way to keep separate log4j files for method level?
Its possible. Yo need to create different logger instances in a class say logger, logger1, logger2 and these should point to different files. Although they will use the same base package to cover but you can move logs in different files for different methods
Here I am posting sample code for configuring multiple loggers.
I have configured my log4j file in this way.
log4j.rootLogger = INFO , stdout
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.appender.pageOneLog=org.apache.log4j.FileAppender
log4j.appender.pageOneLog.File=C:/work/logs/pageOneLog.log
log4j.appender.pageOneLog.layout=org.apache.log4j.PatternLayout
log4j.appender.pageOneLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.appender.pageTwoLog=org.apache.log4j.FileAppender
log4j.appender.pageTwoLog.File=C:/work/logs/pageTwoLog.log
log4j.appender.pageTwoLog.layout=org.apache.log4j.PatternLayout
log4j.appender.pageTwoLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.category.pageOneLogger=INFO, pageOneLog
log4j.additivity.pageOneLogger=false
log4j.category.pageTwoLogger=INFO, pageTwoLog
log4j.additivity.pageTwoLogger=false
Then use this loggers in the Java code following manner.
Logger log1 = Logger.getLogger("pageOneLogger");
Logger log2 = Logger.getLogger("pageTwoLogger");

How to use Logger inside a Resque's worker in a pure ruby application

I have a ruby application (not Rails) using Resque. I'd like to know what's going on in one of the worker I have.
To do that, I use the Logger class as stated in the officiel documentation.
Below is how I log inside a worker:
require 'resque'
require 'logger'
<code>
Resque.logger = Logger.new File.new('logfile.log', 'a')
Resque.logger.info "Whatever"
However, when running my worker, nothing is actually being logged. It's as if the worker is actually ignoring all those log instructions. No error is raised. The other pieces of code actually work - only the logging part is ignored.
I tried to use the logger class itself (ie logger = Logger.new) but the result is the same.
Do you have any idea on how I can actually log something inside my resque worker?
Thanks!
Use the following:
Logger.new(path_to_log_file).info(anything)
You are missing the log level to enabled printing info logs, according to the documentation you linked there, you can use something like this
Resque.logger.level = Logger::DEBUG
then if you look into Logger docs it lists levels as
DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
so if you are using logger.info you either need Logger::DEBUG or Logger::INFO to have the logged string to show up.
Also make sure the logger initialization is run by the process running the workers, and not just the process enqueueing jobs.
my environment: rails 5.0.1, resque: 1.26.0.
I tried config the resque logger in config/initializers/resque.rb and lib/tasks/resuqe.rake, they neither work for me.
but config the resque logger inside every job, that works for me, although it is not perfect.
# update_xxx_job.rb
class UpdateXxxJob
def self.perform
Resque.logger = Logger.new("#{Rails.root}/log/resque.log")
Resque.logger.level = Logger::DEBUG
Resque.logger.info 'Job starts'
...
end
end
more details in another answer.

What is the "right" way to log while running in Sinatra's application scope?

I am playing around with writing a Sinatra app. I'd like to log something from the configuration blocks. However, that runs in the application scope, which doesn't include the logger methods if I do enable :logging in my configure block. Is there some normal way to log messages from the configure blocks while respecting whatever log configuration I have in effect?
Currently, I do something like the following:
class Blah < Sinatra::Base
configure do
enable :logging
##log = Logger.new("/dev/stderr")
##log.info "blah"
end
end
I'd rather use whatever logger is configured and default to one setup by the enable :logger line. Something similar to the following would be ideal:
class Blah < Sinatra::Base
configure do
enable :logging
logger.info "blah"
end
end
As of 1.3 (i think) Sinatra ships with a logger like you described, but it writes by default to STDOUT and STDERR, if you want to hit it to a file add this to your config.ru:
logger = Logger.new('log/awesome_app.log')
use Rack::CommonLogger, logger
run AwesomeApp

Heroku logging not working

I've got a rails 3.1 app deployed on Heroku Cedar. I'm having a problem with the logging. The default rails logs are working just fine, but when I do something like:
logger.info "log this message"
In my controller, Heroku doesn't log anything. When I deploy my app I see the heroku message "Injecting rails_log_stdout" so I think calling the logger should work just fine. Puts statements end up in my logs. I've also tried other log levels like logger.error. Nothing works. Has anyone else seen this?
MBHNYC's answer works great, but it makes it difficult to change the log level in different environments without changing the code. You can use this code in your environments/production.rb to honor an environment variable as well as have a reasonable default:
# https://github.com/ryanb/cancan/issues/511
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get((ENV["LOG_LEVEL"] || "INFO").upcase)
Use this command to set a different log level:
heroku config:set LOG_LEVEL=error
I was just having the same issue, solved by using the technique here:
https://github.com/ryanb/cancan/issues/511
Basically, you need to specify the logger outputs to STDOUT, some gems interfere with the logger and seem to hijack the functionality (cancan in my case).
For the click lazy, just put this in environments/production.rb
config.logger = Logger.new(STDOUT)
config.log_level = :info
As of the moment, it looks like heroku injects these two plugins when building the slug:
rails_log_stdout - https://github.com/ddollar/rails_log_stdout
rails3_server_static_assets - https://github.com/pedro/rails3_serve_static_assets
Anything sent to the pre-existing Rails logger will be discarded and will not be visible in logs. Just adding this for completeness for anyone else who ends up here.
The problem, as #MBHNYC correctly addressed, is that your logs are not going to STDOUT.
Instead of configuring manually all that stuff, Heroku provides a gem that does this all for you.
Just put
gem 'rails_12factor', group: :production
in your Gemfile, bundle, and that's it!
NOTE: This works both for Rails 3 and 4.
Source: Rails 4 on Heroku

Resources