Search in sources :

Example 1 with LogLevel

use of com.google.appengine.api.log.LogService.LogLevel in project teammates by TEAMMATES.

the class CompileLogsAction method getErrorLogs.

private List<AppLogLine> getErrorLogs() {
    LogService logService = LogServiceFactory.getLogService();
    long endTime = new Date().getTime();
    // Sets the range to 6 minutes to slightly overlap the 5 minute email timer
    long queryRange = 1000 * 60 * 6;
    long startTime = endTime - queryRange;
    LogQuery q = LogQuery.Builder.withDefaults().includeAppLogs(true).startTimeMillis(startTime).endTimeMillis(endTime).minLogLevel(LogLevel.ERROR);
    Iterable<RequestLogs> logs = logService.fetch(q);
    List<AppLogLine> errorLogs = new ArrayList<>();
    for (RequestLogs requestLogs : logs) {
        List<AppLogLine> logList = requestLogs.getAppLogLines();
        for (AppLogLine currentLog : logList) {
            LogLevel logLevel = currentLog.getLogLevel();
            if (LogLevel.FATAL == logLevel || LogLevel.ERROR == logLevel) {
                errorLogs.add(currentLog);
            }
        }
    }
    return errorLogs;
}
Also used : LogQuery(com.google.appengine.api.log.LogQuery) ArrayList(java.util.ArrayList) AppLogLine(com.google.appengine.api.log.AppLogLine) RequestLogs(com.google.appengine.api.log.RequestLogs) LogService(com.google.appengine.api.log.LogService) Date(java.util.Date) LogLevel(com.google.appengine.api.log.LogService.LogLevel)

Aggregations

AppLogLine (com.google.appengine.api.log.AppLogLine)1 LogQuery (com.google.appengine.api.log.LogQuery)1 LogService (com.google.appengine.api.log.LogService)1 LogLevel (com.google.appengine.api.log.LogService.LogLevel)1 RequestLogs (com.google.appengine.api.log.RequestLogs)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1