@GET @Path("/system/{component-id}/{service-id}/logs") public void sysList( HttpRequest request, HttpResponder responder, @PathParam("component-id") String componentId, @PathParam("service-id") String serviceId, @QueryParam("start") @DefaultValue("-1") long fromTimeSecsParam, @QueryParam("stop") @DefaultValue("-1") long toTimeSecsParam, @QueryParam("escape") @DefaultValue("true") boolean escape, @QueryParam("filter") @DefaultValue("") String filterStr) { try { TimeRange timeRange = parseTime(fromTimeSecsParam, toTimeSecsParam, responder); if (timeRange == null) { return; } Filter filter = FilterParser.parse(filterStr); LoggingContext loggingContext = LoggingContextHelper.getLoggingContext( Constants.SYSTEM_NAMESPACE, componentId, serviceId); ChunkedLogReaderCallback logCallback = new ChunkedLogReaderCallback(responder, logPattern, escape); logReader.getLog( loggingContext, timeRange.getFromMillis(), timeRange.getToMillis(), filter, logCallback); logCallback.close(); } catch (IllegalArgumentException e) { responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage()); } catch (Throwable e) { LOG.error("Caught exception", e); responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } }
private void doGetLogs( HttpResponder responder, LoggingContext loggingContext, long fromTimeSecsParam, long toTimeSecsParam, boolean escape, String filterStr, @Nullable RunRecord runRecord) { try { TimeRange timeRange = parseTime(fromTimeSecsParam, toTimeSecsParam, responder); if (timeRange == null) { return; } Filter filter = FilterParser.parse(filterStr); ReadRange readRange = new ReadRange( timeRange.getFromMillis(), timeRange.getToMillis(), LogOffset.INVALID_KAFKA_OFFSET); readRange = adjustReadRange(readRange, runRecord); ChunkedLogReaderCallback logCallback = new ChunkedLogReaderCallback(responder, logPattern, escape); logReader.getLog( loggingContext, readRange.getFromMillis(), readRange.getToMillis(), filter, logCallback); logCallback.close(); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (IllegalArgumentException e) { responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage()); } catch (Throwable e) { LOG.error("Caught exception", e); responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } }