How to save Heroku logs to text file
You can try this:
heroku logs -n number_of_lines --app application_name >> file_name
>>
operator will appends the command output to the end of a file : file_name
however, heroku keeps the last 1,500 lines of consolidated logs. If you’d like to persist more than 1,500 lines for long-term storage, search, alerting, filtering and other processing, you can use logging Add-on Providers.
Save Logs on Heroku with Node
One interesting option could be using Papertrail: there is a free plan and with it you get a REST API to query the logs (you can then customise what users see/download).
Papertrail has Heroku integration so pushing the logs from your application should be pretty simple. You can then query/export what your need implementing access via the REST API.
Heroku has also a Papertrail add-on which I think it is the same concept as above but running on Heroku cloud.
Obviously the free plan has a short data retention, you will need to see if this works for you.
How to store heroku logs for data science purposes?
Really the best solution is probably to setup the heroku app to also pipe your logs into an S3 bucket or something like that. Though perhaps you want to set it up so it only sends the log data you are actually interested in. Even better if you can get something that does this for you.
Looks like PaperTrail at least allows this. Here is the current documentation link:
https://documentation.solarwinds.com/en/Success_Center/papertrail/Content/kb/how-it-works/automatic-s3-archive-export.htm?cshid=pt-how-it-works-automatic-s3-archive-export
Though it might get rather costly depending on the volume of logs you need to handle to use an outside service. Otherwise, you may just need to roll your own solution (or better yet, look for gems that can help)
Reformat default heroku log then redirect to output file
Figured this out using a command from I/O redirect: Used this example and tailored it to what I needed to do: COMMAND_OUTPUT > # Redirect stdout to a file. # Creates the file if not present, otherwise overwrites it.
I wanted to output my heroku log to a file called logs.txt -
heroku logs > logs.text
This worked and I found the file - logs.txt in my sublime directory
Heroku production.log file location
The heroku addon logging:expanded no longer exists. Some gems mask the logger output too, so for working answers see this slightly more recent stack overflow post
To summarise, the nicest solution is to add the following to your config/production.rb file:
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get((ENV["LOG_LEVEL"] || "INFO").upcase)
Then, once you've pushed that to heroku, you can see all the logging as it happens with the following command:
heroku logs --tail
heroku - how to see all the logs
Update (thanks to dawmail333):
heroku logs -n 1500
or, to tail the logs live
heroku logs -t
Heroku log documentation
If you need more than a few thousand lines you can Use heroku's Syslog Drains
Alternatively (old method):
$ heroku run rails c
File.open('log/production.log', 'r').each_line { |line| puts line }
Related Topics
Rvm and Osx Lion - Rvm 'Forgets' Gemsets on System Restart
Removing or Overriding an Activerecord Validation Added by a Superclass or Mixin
Creating a Setter Method That Takes Extra Arguments in Ruby
Version Sort (With Alphas, Betas, etc.) in Ruby
Converting a Unique Seed String into a Random, Yet Deterministic, Float Value in Ruby
Why Does Ruby Builder::Xmlmarkup Add Inspect Tag to Xml
Error Loading Media: File Could Not Be Played Error in Jw_Player Rails
Cast Between String and Classname
Ruby on Rails: How to Add a CSS File with Rails Project
React Error (Only a Reactowner Can Have Refs.)
Rails Cannot Load Such File -- MySQL2/Mysql2 (Loaderror)
Rspec Commandline Variable Input
Rails "Action" Params Key Conflict
Why a Module's Singleton Method Is Not Visible in Downstream Eigenclasses Where It Gets Mixed
How to Merge Consecutive Repeating Elements in an Array
Generate All "Unique" Subsets of a Set (Not a Powerset)
How to Check If a String Has at Least One Number in It Using Ruby