Guest User

Untitled

a guest
Feb 24th, 2018
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. # Logs
  2.  
  3. ## Log levels
  4.  
  5. From 0 to 5 in severity:
  6.  
  7. * `debug` - for debugging purposes, only
  8. * `info` - an informative message
  9. * `warn` - this may or may not be an issue
  10. * `error` - this is an issue, but the application can continue running
  11. * `fatal` - this is and issue, and the application should halt
  12. * `unknown` - we don't know (?)
  13.  
  14. A corresponding `Rails.logger.level` method exists for each of these levels.
  15.  
  16. ## Logging important events in the application
  17.  
  18. When writing to the log, give the developer some "breadcrumbs" to follow.
  19. Specify the class name and method name that is writing to the log.
  20.  
  21. ```
  22. msg = "[#{self.class.name}##{__method__}] something important happened that we should log."
  23. Rails.logger.info(msg)
  24. ```
  25.  
  26. If you are `rescue`ing, it probably makes sense to log the error, as well.
  27.  
  28. ```
  29. begin
  30. # some code that might fail
  31. rescue StandardError => err
  32. Rails.logger.error("[#{self.class.name}##{__method__}] raised an error.")
  33. Rails.logger.error(err)
  34. # handle the error
  35. end
  36. ```
  37.  
  38. ## Download Logs from Production
  39.  
  40. ```
  41. $ scp -p ubuntu@wobbe.workbar.com:~/wobbe/current/log/* ~/path/to/wobbe/logs
  42. ```
  43.  
  44. ## Searching Logs
  45.  
  46. The following command will show you three lines before and three lines after any
  47. occurrence of `ClassName`.
  48.  
  49. ```bash
  50. $ cat production.log | grep -B 3 -A 3 "ClassName"
  51. ```
Add Comment
Please, Sign In to add comment