Subversion Repositories SmartDukaan

Rev

Rev 2965 | Rev 3445 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2965 Rev 3073
Line 19... Line 19...
19
import org.apache.commons.lang.StringUtils;
19
import org.apache.commons.lang.StringUtils;
20
import org.apache.log4j.Logger;
20
import org.apache.log4j.Logger;
21
import org.json.JSONObject;
21
import org.json.JSONObject;
22
 
22
 
23
public class DataLogger {
23
public class DataLogger {
-
 
24
    /**
-
 
25
     * If it fails to log the data to google app engine, we log the event locally to data.log using log4j.
-
 
26
     */
24
    private static Logger log = Logger.getLogger(DataLogger.class);
27
    private static Logger log = Logger.getLogger(DataLogger.class);
-
 
28
    
-
 
29
    /**
-
 
30
     * RootLogger to be used internal logging of this class.
-
 
31
     */
25
    private static Logger rootLogger = Logger.getRootLogger();
32
    private static Logger rootLogger = Logger.getRootLogger();
-
 
33
    
-
 
34
    /**
-
 
35
     * Logger to post data to google app engine.
-
 
36
     */
26
    private static ExecutorService asyncDataLogger = Executors.newSingleThreadExecutor();
37
    private static ExecutorService asyncDataLogger = Executors.newSingleThreadExecutor();
27
    private static ExecutorService asyncSocialDataLogger = Executors.newSingleThreadExecutor();
38
    private static ExecutorService asyncSocialDataLogger = Executors.newSingleThreadExecutor();
28
    private static ResourceBundle properties = ResourceBundle.getBundle(DataLogger.class.getName());
39
    private static ResourceBundle properties = ResourceBundle.getBundle(DataLogger.class.getName());
29
    private static String googleAppUrl = properties.getString("googleappurl");
40
    private static String googleAppUrl = properties.getString("googleappurl");
30
 
41
 
Line 54... Line 65...
54
                    conn.setDoOutput(true);
65
                    conn.setDoOutput(true);
55
                    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
66
                    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
56
                    wr.write(data);
67
                    wr.write(data);
57
                    wr.close();
68
                    wr.close();
58
                    
69
                    
59
                    BufferedReader in = new BufferedReader(
-
 
60
                            new InputStreamReader(conn.getInputStream()));
-
 
61
 
-
 
62
                    while (in.readLine() != null);
-
 
63
                    in.close();
70
                    conn.getInputStream().close();
64
 
-
 
65
                } catch (Exception e) {
71
                } catch (Exception e) {
66
                    rootLogger.error("Unable to post data to web data log", e);
72
                    rootLogger.error("Unable to post data to web data log", e);
67
                    log.info(eType.name() + ", " + sessionId + ", " + Long.toString(userId) + ", " + email + ", " + strToWrite);
73
                    log.info(eType.name() + ", " + sessionId + ", " + Long.toString(userId) + ", " + email + ", " + strToWrite);
68
                }
74
                }
69
            }
75
            }
Line 105... Line 111...
105
                    Logger.getRootLogger().warn(e);
111
                    Logger.getRootLogger().warn(e);
106
                }
112
                }
107
            }
113
            }
108
        });
114
        });
109
    }
115
    }
-
 
116
    
-
 
117
    public static void main(String[] args) {
-
 
118
        DataLogger.logData(EventType.NEW_SESSION, "FDTWSYTW", 12, "vmalik@gmail.com", "Test");
-
 
119
    }
110
}
120
}
111
121