I'm trying to use https://github.com/roidrage/lograge on a Rails 6.1 app
According to lograge README
I have configured it as follows
# config/production.rb
Rails.application.configure do
...
config.log_level = :info
config.lograge.keep_original_rails_log = true
config.lograge.logger = ActiveSupport::Logger.new "#{Rails.root}/log/lograge_#{Rails.env}.log"
config.lograge.custom_options = lambda { |event| { time: Time.now } }
end
However, nothing is logged to lograge_production.log.
bash-5.1$ cat lograge_production.log
# Logfile created on 2022-09-05 11:11:54 +0000 by logger.rb/v1.4.2
Even when there is a fatal error.
bash-5.1$ cat production.log
...
F, [2022-09-05T11:33:24.526190 #14] FATAL -- : [1f22ef13-99e0-4247-ad58-eea8d9255940]
[1f22ef13-99e0-4247-ad58-eea8d9255940] NoMethodError (undefined method `requires_article' for nil:NilClass
Did you mean? require_or_load):
[1f22ef13-99e0-4247-ad58-eea8d9255940]
[1f22ef13-99e0-4247-ad58-eea8d9255940] app/models/operation.rb:21:in `block in <class:Operation>'
[1f22ef13-99e0-4247-ad58-eea8d9255940] app/controllers/operations_controller.rb:93:in `create'
bash-5.1$ ls
The issue is the same one described here https://github.com/roidrage/lograge/issues/298.
Am I missing anything?
Related
I don't know that much about RUBY, just thought that you guys might help me with this. I'm using Storyblok as my headless CMS and JEKYLL when I'm building serve it this is the error that I got;
33: from C:/project/test/_plugins/storyblok_generator.rb:8:in `generate'
32: from C:/project/test/_plugins/storyblok_cms/generator.rb:12:in `generate!'
C:/project/test/vendor/cache/ruby/2.7.0/gems/storyblok-3.0.1/lib/storyblok/client.rb:354:in `block (2 levels) in find_and_fill_links': undefined method `[]' for nil:NilClass (NoMethodError)
the code below is from _plugins/storyblok_cms/generator.rb
def generate!
timestamp = Time.now.to_i
links = client.links(cv: timestamp)['data']['links']
stories = client.stories(per_page: 100, page: 1, cv: timestamp)['data']['stories'] #line 12
stories.each do |story|
# create all pages except global (header,footer,etc.)
content_type = story['content']['component']
if content_type != 'shared'
site.pages << create_page(site, story, links)
end
rescue UnknownContentTypeError => e
# for production, raise unknown content type error;
# for preview and other environments, issue an warning only since the content_type might be available
# but the code handling that content type might be in a different branch.
Jekyll.env == 'production' ? raise : Jekyll.logger.warn(e.message)
end
site.data['stories'] = stories
site.data['articles'] = stories.select { |story| story['full_slug'].start_with?('articles') }
site.data['shared'] = stories.select { |story| story['full_slug'].start_with?('shared') }
end
the code below is from _plugins/storyblok_generator.rb
require "storyblok"
module Jekyll
class StoryblokGenerator < Jekyll::Generator
safe true
def generate(site)
StoryblokCms::Generator.new(site).generate! #line 8
end
end
end
Additional Info:
ruby version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32]
jekyll version: jekyll 4.2.1
OS: Windows 10
I've actually found the solution to this, So this error occurs because I have created a page template in Block Library in Storyblok and then firing bundle exec jekyll serve command in terminal without creating the page template source/file in my project directory.
So I have an about_us block (content-type) in Block Library created and then when I fire bundle exec jekyll serve without creating an about_us.html first in _layouts folder, It would trigger the error.
Solution;
Make sure to create the source/file first in the _layouts folder if you have created a block (content-type) in block library.
I'm using Rails 5.2.5 and I want to change the log level when I use rails console.
I want to stress that I don't want to change any file in the project, but just to do the change from the console.
I saw some suggestions to run:
conf.log_level = :debug
in the console, but I got the error
NameError (undefined local variable or method `config' for
main:Object) Did you mean? conf
I also tried to execute
conf.log_level = :debug
but I also got the error:
Traceback (most recent call last):
2: from (irb):11
1: from (irb):11:in `rescue in irb_binding'
Do you have any suggestion?
Change YourApp configuration (YourApplocated at config/environment/[environment].rb
YourApp.configure do
config.log_level = :info
end
Or you can use Rails.application.configure
2.5.8 :005 > Rails.application.configure do
2.5.8 :006 > puts(config.log_level)
2.5.8 :007?> end
debug
=> nil
2.5.8 :008 > Rails.application.configure do
2.5.8 :009 > config.log_level = :info
2.5.8 :010?> end
=> :info
2.5.8 :011 > Rails.application.configure do
2.5.8 :012 > puts(config.log_level)
2.5.8 :013?> end
info
Rails 3.2
I've used logger.info successfully in the past. Today, I was trying to debug a model's action, and it's breaking my application. My code (in models/admin_ability.rb):
can :decline, Ticket do |ticket|
if ticket.persisted?
logger.info("File: #{__FILE__ } -- LINE: #{__LINE__ }")
executor = ticket.executor
ticket_profile = ticket.ticket_profile
decliners = ticket.decliners
suitable_companies = ''
suitable_companies = ticket_profile.suitable_companies(decliners, ticket.customer, ticket.customer_info.zip, ticket.requested_date_start,
false, false) if decliners.blank?
suitable_companies.delete(ticket.executor)
!(suitable_companies.compact).blank?
end
end
Here's the error message:
undefined local variable or method `logger' for #<AdminAbility:0x007f8382bfd3f0>
Rails.root: /home/app
Application Trace | Framework Trace | Full Trace
app/models/admin_ability.rb:40:in `block in initialize'
Line 40 is:
logger.info("File: #{__FILE__ } -- LINE: #{__LINE__ }")
Any ideas?
Call logger on the Rails constant: Rails.logger.info
I am using Ruby on Rails. I am trying to implement https://www.kraken.com/help/api
Incase it isn't obvious, my knowledge of implementing API's and gems is very basic.
I go to the "example-api-code" paragraph and I get to https://github.com/leishman/kraken_ruby
I include the gem and do the bundle.
Now we get to "Usage" "Create A Client"
I assume I put the following in config/kraken.rb
API_KEY = '3bH+M/nLp......'
API_SECRET = 'wQG+7Lr9b.....'
kraken = Kraken::Client.new(API_KEY, API_SECRET)
time = kraken.server_time
time.unixtime #=> 1393056191
I wanted to test something simple, such as displaying the time.
I put the following code in my views/welcome/index.html.erb file, but then I get an error.
<p><%= kraken.server_time %></p>
-> ActionView::Template::Error (undefined local variable or method `kraken' for #<#<Class:0x007f95c6246ba8>:0x007f95c6245eb0>):
Trying this code in my html.erb file and it gives me another error
<p><%= #kraken.server_time %></p>
-> ActionView::Template::Error (undefined method `server_time' for nil:NilClass):
-------------------------------------------------------------------------------
EDIT: Solutions Attempts, TLDR NameError (uninitialized constant...
# Gladis
Using your solution I get this error
->! Unable to load application: SyntaxError: /app/app/controllers/welcome_controller.rb:5: dynamic constant assignment
-> API_KEY = '...'
So I tried
def index
#kraken = Kraken::Client.new('3bH+M/nLp...', 'wQG+7Lr9b...')
time = #kraken.server_time
time.unixtime #=> 1393056191
end
and got this new error
NameError (uninitialized constant WelcomeController::Kraken):
app/controllers/welcome_controller.rb:5:in `index'
# Pavel Tkackenko
Your first solution (wrapping in singleton-like class) gives me this error.
ActionView::Template::Error (uninitialized constant ActionView::CompiledTemplates::KrakenClient):
app/views/welcome/index.html.erb:1:in `_app_views_welcome_index_html_erb__3584347874708863751_70226442404480'
1: <p><%= KrakenClient.get.server_time %></p>
Your second solutions (monkey-patch) gives me the this error.
ActionView::Template::Error (uninitialized constant ActionView::CompiledTemplates::Kraken):
1: <p><%= Kraken.client.server_time %></p>
app/views/welcome/index.html.erb:1:in `_app_views_welcome_index_html_erb___3719740865851336982_69820265644620'
Moving /config/kraken.rb to /config/initializers/kraken.rb using Pavel's method
Wrapping it in singleton-like class gives me this error (infact, it doesn't even let me host the server)
->When I host it on my local computer with bin/rails server
/config/initializers/kraken.rb:6:in `<class:KrakenClient>': uninitialized constant KrakenClient::Kraken (NameError)
/config/initializers/kraken.rb:1:in `<top (required)>'
->When I host it on heroku
Running: rake assets:precompile
rake aborted!
NameError: uninitialized constant KrakenClient::Kraken
/config/initializers/kraken.rb:5:in `<class:KrakenClient>'
/config/initializers/kraken.rb:1:in `<top (required)>'
...
/config/environment.rb:5:in `<top (required)>'
With monkey-patch I get this error
ActionView::Template::Error (uninitialized constant Kraken::Client):
1: <p><%= Kraken.client.server_time %></p>
config/initializers/kraken.rb:8:in `client'
app/views/welcome/index.html.erb:1:in `_app_views_welcome_index_html_erb___577296263292451462_70097201303100'
If you got it to work on your computer, I would be happy to use your code as a skeleton (I am assuming this will be easier than figuring out what's wrong on my side).
Put this code in WelcomeController.rb
def index
API_KEY = '3bH+M/nLp......'
API_SECRET = 'wQG+7Lr9b.....'
#kraken = Kraken::Client.new(API_KEY, API_SECRET)
time = #kraken.server_time
time.unixtime #=> 1393056191
end
In view under this controller put:
<p><%= #kraken.server_time %></p>
kraken = Kraken::Client.new(API_KEY, API_SECRET)
kraken here is local variable. If you put it into config/kraken.rb, it will not be accessible outside.
There are different solutions. One is to wrap it in singleton-like class:
# config/initializers/kraken.rb
class KrakenClient
API_KEY = '3bH+M/nLp......'
API_SECRET = 'wQG+7Lr9b.....'
##config = Kraken::Client.new(API_KEY, API_SECRET)
def self.get
##config
end
end
# index.html.erb
<p><%= KrakenClient.get.server_time %></p>
Another one approach is to monkey-patch Kraken itself:
# config/initializers/kraken.rb
class Kraken
API_KEY = '3bH+M/nLp......'
API_SECRET = 'wQG+7Lr9b.....'
class << self
def client
#client ||= Kraken::Client.new(API_KEY, API_SECRET)
end
end
end
# index.html.erb
<p><%= Kraken.client.server_time %></p>
How to make rake-offline work in rails 3.2.11 ?
I added initializer
offline = Rack::Offline.configure do
#cache "images/masthead.png"
public_path = Rails.public_path
Dir[public_path.join("javascripts/*.js")].each do |file|
cache file.relative_path_from(public_path)
end
network "/"
end
I added in routes
match "/application.manifest" => Rails::Offline
Rack::Offline.configure do
cache "assets/application.js"
cache "assets/application.css"
network "/"
end
and added manifest in html tag.
It throws error
/initializers/offline.rb:5:in `block in <top (required)>': undefined method `join' for "/Sites/Ruby/project/public":String (NoMethodError)
In Rails 3.2.11, Rails.public_path returns a String, not a Pathname object. (It looks like Rails master has it returning a Pathname object which is why rack-offline's documentation might say to use it that way).
Try this instead:
public_path = Pathname.new(Rails.public_path)
See https://github.com/wycats/rack-offline/issues/7