在进行重要的数据库更改时,我有一堆日志记录语句。例如,
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
我可以通过搜索heroku logs
的输出来获取这些内容,但似乎heroku只保留了大约1000行日志记录,因此我的语句被推出。有没有办法将这些保存到文件中,只保留" INFO"声明达到一定数量的行(类似于10000)?
或者,可以"关闭"输出如
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]]
答案 0 :(得分:0)
heroku有几个附加组件允许您将日志重定向到其他位置。但是,您可能需要考虑您认为不重要的输出对于在出现故障时追踪问题非常重要。虽然“John Doe更新了他的个人资料”并不是非常有用 - 我的意思是,如果它是恶意的,那你打算用什么呢?
也可以从日志中看到{{1}}被调用的参数以及参数是否有效。
如果您需要在用户编辑资源时进行审核,则可以使用像papertrail这样的gem。