Comments (8)
I tried the same solution as in rails, but I don't see anything in the console:
if ::Rails.logger.respond_to?(:broadcast_to)
Rails.logger = ActiveSupport::BroadcastLogger.new(Rails.logger, console)
else
Rails.logger.extend ActiveSupport::Logger.broadcast console
end
from telegram-bot.
UPDATE: I checked an old version because I didn't really remember the expected output and you are completely right, logs are missing.
Hey @mario-amazing I got the same error and applied the same patch as you (different condition but still) and it seems to be working fine
diff --git a/lib/tasks/telegram-bot.rake b/lib/tasks/telegram-bot.rake
index 01c5cd9..85371a6 100644
--- a/lib/tasks/telegram-bot.rake
+++ b/lib/tasks/telegram-bot.rake
@@ -7,7 +7,11 @@ namespace :telegram do
Rake::Task['environment'].invoke
if ENV.fetch('LOG_TO_STDOUT') { Rails.env.development? }.present?
console = ActiveSupport::Logger.new(STDERR)
- Rails.logger.extend ActiveSupport::Logger.broadcast console
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1')
+ Rails.logger = ActiveSupport::BroadcastLogger.new(Rails.logger, console)
+ else
+ Rails.logger.extend ActiveSupport::Logger.broadcast console
+ end
end
Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default)
end
class TelegramController < Telegram::Bot::UpdatesController
# ... Unrelated code
def message(message)
Rails.logger.info("Received a message!!")
end
bin/rails telegram:bot:poller
Received a message!!
from telegram-bot.
So the thing is that when invoking the environment
task we are already creating instances of Telegram::Bot::UpdatesPoller
and those instances memoize the initial logger.
Once we overwrite the logger Rails.logger = ActiveSupport::BroadcastLogger.new(console)
new instances will have the correct one but the others won't.
If we update the Rails logger before invoking the environment
task, all instances of the poller will have the correct logger.
diff --git a/lib/tasks/telegram-bot.rake b/lib/tasks/telegram-bot.rake
index 01c5cd9..3b5c433 100644
--- a/lib/tasks/telegram-bot.rake
+++ b/lib/tasks/telegram-bot.rake
@@ -4,10 +4,15 @@ namespace :telegram do
'Use LOG_TO_STDOUT to enable/disable broadcasting.'
task :poller do
ENV['BOT_POLLER_MODE'] = 'true'
- Rake::Task['environment'].invoke
if ENV.fetch('LOG_TO_STDOUT') { Rails.env.development? }.present?
console = ActiveSupport::Logger.new(STDERR)
- Rails.logger.extend ActiveSupport::Logger.broadcast console
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1')
+ Rails.logger = ActiveSupport::BroadcastLogger.new(console)
+ Rake::Task['environment'].invoke
+ else
+ Rake::Task['environment'].invoke
+ Rails.logger.extend ActiveSupport::Logger.broadcast console
+ end
end
Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default)
end
Don't know if this is the best solution though, @mario-amazing could you do some testing in your project to confirm this works?
from telegram-bot.
@epergo Results:
Rails 7.1 logs with /start command:
Rails 7.0
Rails.logger.level
=> 0
from telegram-bot.
Did you first apply the patch in my second message?
from telegram-bot.
ofc, without this patch I can't even start a poll
from telegram-bot.
Hello. I have the same issue.
I had to make a rake task to run on dev:
namespace :telegram do
desc "Start Telegram bot"
task :poller do
ENV['BOT_POLLER_MODE'] = 'true'
if ENV.fetch('LOG_TO_STDOUT') { Rails.env.development? }.present?
console = ActiveSupport::Logger.new(STDERR)
if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1')
Rails.logger = ActiveSupport::BroadcastLogger.new(console)
Rake::Task['environment'].invoke
else
Rake::Task['environment'].invoke
Rails.logger.extend ActiveSupport::Logger.broadcast console
end
end
Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default)
end
end
It works when I run it through
bundle exec rake telegram:poller
but it doesn't work when I run it through Foreman.
Procfile.dev:
web: env RUBY_DEBUG_OPEN=true && unset PORT && puma -C config/puma.rb
log: tail -f log/development.log
js: yarn build --watch
css: yarn build:css --watch
sidekiq: bundle exec sidekiq -C config/sidekiq.yml
telegram: bundle exec rake telegram: poller
foreman start -f Procfile.dev
12:06:22 telegram.1 | rake aborted!
12:06:22 telegram.1 | Telegram::Bot::NotFound: Not Found (Telegram::Bot::NotFound)
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/client.rb:67:in `request'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/async.rb:151:in `request'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/client/api_helper.rb:22:in `block (2 levels) in define_helpers'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/updates_poller.rb:71:in `block in fetch_updates'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/async.rb:138:in `async'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/updates_poller.rb:71:in `fetch_updates'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/updates_poller.rb:58:in `run'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/updates_poller.rb:47:in `start'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/telegram-bot-0.16.0/lib/telegram/bot/updates_poller.rb:21:in `start'
12:06:22 telegram.1 | /media/ruslan/team/charity_crew/lib/tasks/telegram-bot.rake:15:in `block (2 levels) in <main>'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `eval'
12:06:22 telegram.1 | /home/ruslan/.rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `<main>'
12:06:22 telegram.1 | Tasks: TOP => telegram:poller
from telegram-bot.
if ::Rails.logger.respond_to?(:broadcast_to)
::Rails.logger.broadcast_to(console)
else
Rails.logger.extend ActiveSupport::Logger.broadcast console
end
from telegram-bot.
Related Issues (20)
- EditMessageMedia not working HOT 1
- Allow to subscribe to "chat_member" updates when using web hooks HOT 3
- Webhook secret_token verification HOT 4
- Default parse_mode HOT 3
- Telegram-bot poller mode with sentry HOT 3
- [Feature request] Add a caption to sendMediaGroup HOT 1
- Does gem support providing MarkdownV2 style? HOT 6
- Poller connection issues HOT 1
- "save_context" method is not working properly in group chat HOT 1
- How to use `set_my_commands`? HOT 1
- Rails 7.1 support HOT 1
- Strange rspec shared_conext `telegram/bot/integration/rails` behavior HOT 3
- Strange thing with api_methods.txt HOT 3
- [Feature] Webhook mode telegram server validation HOT 4
- Dispatch error ArgumentError (wrong number of arguments (given 3, expected 2)) HOT 1
- New 7.0 API HOT 3
- Is there any way to create an alias or something similar? HOT 1
- how can I make additional dispatcher in TelegramWebhookController? HOT 2
- [Bug] Frozen string in logger caused excessive logging HOT 1
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 telegram-bot.