0

I have a bunch of logging statements when important database changes are made. For example,

def update
  @user = User.find(params[:id])
  if @user.update_attributes(user_params)
    logger.info "INFO -- #{Time.now} -- User #{@user.first_name} #{@user.last_name} (ID: #{@user.id}) updated their profile"
    flash[:success] = "Profile updated"
    redirect_to @user
  else
    render 'edit'
  end
end

I can get these by searching through the output of heroku logs, but it seems that heroku only keeps about 1000 lines of logging so my statements get pushed out. Is there a way to save these to a file and keep only the "INFO" statements up to a certain number of lines (something like 10000)?

Alternatively, would it be possible to "turn off" output like

2016-04-20T10:28:52.031573+00:00 app[web.1]:   Role Load (0.8ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'scout') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 135]]
2016-04-20T10:28:52.046090+00:00 app[web.1]:   Role Load (0.8ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'scout') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 143]]
2016-04-20T10:28:52.056567+00:00 app[web.1]:   Rendered layouts/_shim.html.erb (0.1ms)
2016-04-20T10:28:52.060492+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.2ms)
2016-04-20T10:28:52.060925+00:00 app[web.1]: Completed 200 OK in 215ms (Views: 167.9ms | ActiveRecord: 41.7ms)
2016-04-20T10:28:52.048956+00:00 app[web.1]:   User Load (0.8ms)  SELECT  "users".* FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."followed_id" WHERE "relationships"."follower_id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["follower_id", 143]]
2016-04-20T10:28:52.057903+00:00 app[web.1]:   CACHE (0.0ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 165]]
2016-04-20T10:28:52.050240+00:00 app[web.1]:   CACHE (0.0ms)  SELECT  "users".* FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."followed_id" WHERE "relationships"."follower_id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["follower_id", 143]]
2016-04-20T10:28:52.058796+00:00 app[web.1]:   CACHE (0.0ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'der') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 165]]

?

mjswartz
  • 715
  • 1
  • 6
  • 19
  • Possible duplicate of [How to save Heroku logs to text file](http://stackoverflow.com/questions/29910252/how-to-save-heroku-logs-to-text-file) – MurifoX Apr 20 '16 at 13:39

1 Answers1

0

There are several add-ons to heroku that allow you to redirect the logs elsewhere. However you might want to consider that the output you deem unimportant is actually vital for tracking down the problem when something breaks. While "John Doe updated his profile" is not very useful at all - I mean what are you going to with that after the fact if it was malicious?

Also can see from the log anyways that users#update was called and the parameters and if it was valid or not.

If you need to have auditing when users edit resources you can use a gem like papertrail.

max
  • 96,212
  • 14
  • 104
  • 165
  • I'll definitely checkout papertrail. I'm interested in keeping track of who did what at what time in clear text instead of having to dig through the nasty stuff. – mjswartz Apr 20 '16 at 15:55
  • Yeah papertrail sounds like what you want. – max Apr 20 '16 at 22:15