Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use Mail.send(). Log additional info.

  • Loading branch information...
commit a8a5335344021be760bd125c8bd43bab026d1569 1 parent 43796c5
Mustafa Paksoy authored August 31, 2011
30  app/controllers/RequiresLogin.java
@@ -13,6 +13,7 @@
13 13
 import play.Logger;
14 14
 import play.Play;
15 15
 import play.libs.Crypto;
  16
+import play.libs.Mail;
16 17
 import play.libs.OAuth;
17 18
 import play.mvc.Before;
18 19
 import play.mvc.Catch;
@@ -73,25 +74,40 @@ static void logError(Throwable e) {
73 74
             email.addTo(ERROR_EMAIL);
74 75
             email.setSubject(String.format("Error at %s logged: %s", date, e.getClass()));
75 76
             StringBuilder body = new StringBuilder();
76  
-            body.append("Date: ").append(date).append("\n\n");
77  
-            body.append("Message: ").append(e.getMessage()).append("\n\n");
78  
-            body.append("Class: ").append(e.getClass()).append("\n\n");
  77
+            body.append("Date:\t").append(date).append("\n\n");
  78
+            body.append("Session:\t").append(session.get("username")).append("\n\n");
  79
+            body.append("Message:\t").append(e.getMessage()).append("\n\n");
  80
+            body.append("Class:\t").append(e.getClass()).append("\n\n");
79 81
             body.append("Exception trace: ").append(getSTString(e)).append("\n\n");
80 82
             Throwable cause = e.getCause();
81 83
             while (cause != null) {
82  
-	            body.append("\nNew cause\n\n");
83  
-	            body.append("Message: ").append(cause.getMessage()).append("\n\n");
84  
-	            body.append("Class: ").append(cause.getClass()).append("\n\n");
  84
+	            body.append("New cause\n\n");
  85
+	            body.append("Message:\t").append(cause.getMessage()).append("\n\n");
  86
+	            body.append("Class:\t").append(cause.getClass()).append("\n\n");
85 87
 	            body.append("Exception trace: ").append(getSTString(cause)).append("\n\n");
86 88
 	            cause = cause.getCause();
87 89
             }
  90
+            addHttpHeaders(body);
88 91
             email.setMsg(body.toString());
89  
-            email.send();
  92
+            Mail.send(email);
90 93
         } catch (EmailException emailEx) {
91 94
             Logger.error(emailEx, "Failed to send error email to %s. This is really bad :(", ERROR_EMAIL);
92 95
         }
93 96
     }
94 97
     
  98
+    private static void addHttpHeaders(StringBuilder sb) {
  99
+        sb.append("HTTP Headers:\n");
  100
+        for (Header h: request.headers.values()) {
  101
+            sb.append("Header: ").append(h.name).append("\n");
  102
+            sb.append("Value: ");
  103
+            for (String val: h.values) {
  104
+                sb.append(val).append(",");
  105
+            }
  106
+            sb.append("\n");
  107
+        }
  108
+        sb.append("\n\n");
  109
+    }
  110
+
95 111
     private static String getSTString(Throwable t) {
96 112
         StringWriter sw = new StringWriter();
97 113
         PrintWriter pw = new PrintWriter(sw);
2  conf/application.conf
@@ -184,7 +184,7 @@ memcached.host=127.0.0.1:11211
184 184
 # Mail configuration
185 185
 # ~~~~~ 
186 186
 # Default is to use a mock Mailer
187  
-# mail.smtp=mock
  187
+%dev.mail.smtp=mock
188 188
 
189 189
 # Or, specify mail host configuration
190 190
 %prod.mail.smtp.host=smtp.sendgrid.net

0 notes on commit a8a5335

Please sign in to comment.
Something went wrong with that request. Please try again.