What means #some-number in Rails log? - ruby-on-rails

I have log file in Rails 4.
Here is string.
I, [2014-09-30T19:16:23.434591 #6942] INFO -- : Completed 302 Found in 1176ms (ActiveRecord: 4.6ms)
What means number after DATETIME? #6942?

it is process id: PID
Log format: SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
Log sample: I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
http://www.ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html#class-Logger-label-Format

Related

Ruby print JSON value - no implicit conversion of String into Integer

I'm trying to print only the value of a JSON and I'm getting the error no implicit conversion of String into Integer.
Any idea how I can resolve this?
puts test.class
Azure::Armrest::ArmrestCollection
Here is the output of the varaible and I want to print only the quantity value.
puts test
[----] I, [2022-08-23T08:59:20.279357 #550:bc494] INFO -- automation: Method STDOUT: {"id":"/subscriptions/123456/providers/Microsoft.Commerce/UsageAggregates/Daily_BRSDT_20220801_0000","name":"Daily_BRSDT_20220801_0000","type":"Microsoft.Commerce/UsageAggregate","properties":{"subscriptionId":"123456","usageStartTime":"2022-07-31T00:00:00+00:00","usageEndTime":"2022-08-01T00:00:00+00:00","meterName":"Data Transfer Out","meterRegion":"North America","meterCategory":"Bandwidth","meterSubCategory":"Inter-Region","unit":"1 GB","instanceData":"{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/123456/resourceGroups/cloud-shell-storage-centralindia/providers/Microsoft.Compute/virtualMachines/ubuntu975\",\"location\":\"eastus\",\"additionalInfo\":{\"PipelineType\":\"v2\",\"DataTransferDirection\":\"DataTrOut\"}}}","meterId":"dbefcfc1-e3f6-409b-be6d-9cd7b00724a5","infoFields":{},"quantity":9.052455425262451e-07}}
[----] I, [2022-08-23T08:59:20.280435 #550:bc494] INFO -- automation: Method STDOUT: {"id":"/subscriptions/123456/providers/Microsoft.Commerce/UsageAggregates/Daily_BRSDT_20220801_0000","name":"Daily_BRSDT_20220801_0000","type":"Microsoft.Commerce/UsageAggregate","properties":{"subscriptionId":"123456","usageStartTime":"2022-07-31T00:00:00+00:00","usageEndTime":"2022-08-01T00:00:00+00:00","meterName":"Dynamic Public IP","meterCategory":"Virtual Network","meterSubCategory":"IP Addresses","unit":"1 Hour","instanceData":"{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/123456/resourceGroups/cloud-shell-storage-centralindia/providers/Microsoft.Network/publicIPAddresses/Ubuntu975-publicIp\",\"location\":\"eastus\",\"additionalInfo\":{\"IpAddress\":\"20.25.57.9\",\"PlatformType\":\"V2-Agg\"}}}","meterId":"f114cb19-ea64-40b5-bcd7-aee474b62853","infoFields":{},"quantity":1.0}}
puts test["properties"]["quantity"]
[----] E, [2022-08-23T08:59:28.949873 #544:b6620] ERROR -- automation: <AEMethod getcostusage> [no implicit conversion of String into Integer]
/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage:79:in `[]'
/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage:79:in `<main>'
[----] I, [2022-08-23T08:59:28.974301 #544:ac260] INFO -- automation: <AEMethod [/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage]> Ending
If I try JSON.parse(test) then I get this error.
[----] E, [2022-08-23T09:18:39.022825 #553:bcaac] ERROR -- automation: <AEMethod getcostusage> [no implicit conversion of Azure::Armrest::ArmrestCollection into String]
test is an instance of ArmrestCollection, which inherits from Array class (as can be viewed here).
To print the quantity of all elements, you can iterate it and print them each individually:
test.each do |element|
puts element["properties"]["quantity"]
end

Heroku Ruby Website Image Uploading Error

Trying to set up image uploading on my website, but whenever I test uploading an image, it fails and I get these errors in the log... I've looked through so many fixes but none seem to work correctly.
If anyone could point me towards a fix or let me know what exactly is going wrong that would be great. Thanks.
2021-04-18T19:33:58.653571+00:00 app[web.1]: [6e2d06ab-891e-4970-8fbe-2e9fb2868eca] ActiveModel::UnknownAttributeError (unknown attribute 'service_name' for ActiveStorage::Blob.):
2021-04-18T19:33:58.653571+00:00 app[web.1]: [6e2d06ab-891e-4970-8fbe-2e9fb2868eca]
2021-04-18T19:33:58.653572+00:00 app[web.1]: [6e2d06ab-891e-4970-8fbe-2e9fb2868eca] app/controllers/gigs_controller.rb:88:in `upload_photo'
2021-04-18T19:33:58.748015+00:00 app[web.1]: I, [2021-04-18T19:33:58.747897 #4] INFO -- : [16714095-28f1-4c97-8e78-407316f869dd] Started GET "/gigs/6/edit?step=4" for [ip address] at 2021-04-18 19:33:58 +0000```

Is there any thing in rails that helps us to know what and all actions are travelled that a route request

I have a huge rails code many routes and i see the console that says for the route home/index
Processing by HomeController#index as HTML
but i don't even see with binding.pry that the route hit but i get 200OK response in my terminal i see that there are many filters being called but i don't know which filter is being called as there are 100's of modules being include.
Is there a formula that guides us telling which page the action has traversed through which module only in the project but not to the internal rails code like traversing inside the rails gem and all.
I get a very white screen on chrome for localhost:3000/ where there is no layout being loaded. So i need to backtrace to what actions has my route hit and what and all callbacks are involved in performing that action.
Its waste of time with binding.pry putting at lots of places.
I, [2019-11-07T13:41:06.046091 #22077] INFO -- : Started GET "/" for 127.0.0.1 at 2019-11-07 13:41:06 +0530
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
W, [2019-11-07T13:41:07.190395 #22077] WARN -- : Creating scope :track_allowed. Overwriting existing method CustomFieldDefinition.track_allowed.
W, [2019-11-07T13:41:07.190553 #22077] WARN -- : Creating scope :document_allowed. Overwriting existing method CustomFieldDefinition.document_allowed.
W, [2019-11-07T13:41:07.190643 #22077] WARN -- : Creating scope :image_allowed. Overwriting existing method CustomFieldDefinition.image_allowed.
W, [2019-11-07T13:41:07.190724 #22077] WARN -- : Creating scope :video_allowed. Overwriting existing method CustomFieldDefinition.video_allowed.
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
W, [2019-11-07T13:41:07.325206 #22077] WARN -- : Creating scope :by_ids. Overwriting existing method MediaFormat.by_ids.
I, [2019-11-07T13:41:07.334538 #22077] INFO -- : Processing by HomeController#index as HTML
D, [2019-11-07T13:41:07.336651 #22077] DEBUG -- : Track Load (0.6ms) SELECT "tracks".* FROM "tracks" WHERE (tracks.purged_at IS NULL)
I, [2019-11-07T13:41:07.339979 #22077] INFO -- : Completed 200 OK in 5ms (ActiveRecord: 2.3ms | Path: http://localhost:3000/)
If you are assuming that the / (root path) should hit HomeController#index I think you should check your routes.
A specific url always can only hit one action. In this case your log tells us it is processed by the MainController#home method.
Check your routes (in config/routes.rb) and check your root definition.
It should be
root to: 'home#index'
(and also check if there are multiple occurrences)

Ruby on Rails log lines start with "I" or "W"

Noticed that all the lines in Rails log (production.log for example) start with either capital "I" or capital "W". For example
I, [2017-04-04T15:40:40.409423 #15879] INFO -- : [8dd4dd50-2dba-466e-91c3-13e83333db78] Completed 302 Found in 96ms (ActiveRecord: 6.2ms)
I, [2017-04-04T15:40:40.448567 #15866] INFO -- : [e80b7bcc-92be-465a-a9b1-1f39222238cf] Started GET "/bla" for ip at 2017-04-05 15:40:40 +0200
I, [2017-04-04T15:40:40.454994 #15866] INFO -- : [e80b7bcc-92be-465a-a9b1-1f39123138cf] Processing by blaController#index as HTML
Found no explanation for why is it like this and what's the purpose.
It's the standard Logger Format with SeverityID as the first value :
Log format:
SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
Log sample:
I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.

Not nil code that works for both sqlite3 and pg

I have a rails app running sqlite3 in development and pg in production, currently running on Heroku. I am getting an error on my heroku app. I have a column called 'archived' which starts out as nil until the user pushes a button, then the current time gets written into the cell. Then all messages where archived != nil is then ordered by most recent.
Below is a portion of my heroku log:
2013-05-07T22:00:31.775149+00:00 app[web.1]: Completed 500 Internal Server Error in 34ms
2013-05-07T22:00:31.785541+00:00 app[web.1]:
2013-05-07T22:00:31.785541+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR: invalid input syntax for type timestamp: ""
2013-05-07T22:00:31.785541+00:00 app[web.1]: LINE 1: ... "messages".* FROM "messages" WHERE (archived <> '') ORDER ...
2013-05-07T22:00:31.785541+00:00 app[web.1]: ^
2013-05-07T22:00:31.785541+00:00 app[web.1]: : SELECT "messages".* FROM "messages" WHERE (archived <> '') ORDER BY archived desc LIMIT 10):
This tells me that the issue is this line of code from my controller:
#archived_messages = Message.where("archived <> ''").limit(10).order('archived desc')
What should I change this code to so that it works in both sqlite3 and pg?
Thanks in advance.
Got it!
#archived_messages = Message.where("archived IS NOT NULL").limit(10).order('archived desc')
source: Runs locally with SQLite, but on Heroku: PGError: ERROR: syntax error at or near "NULL"

Resources