def listLogs()

in cdslogviewer/app/controllers/LogsController.scala [58:76]


  def listLogs(route:String) = IsAdmin { uid=> request=>
    val base = config.get[String]("cds.logbase")
    val path = Paths.get(base, route)
    if(!path.toString.startsWith(base)) {
      BadRequest(GenericErrorResponse("bad_request","That is not a valid log").asJson)
    } else if(!path.toFile.exists()) {
      NotFound(GenericErrorResponse("not_found","The given route logs do not exist").asJson)
    } else {
      val stream = Source.fromIterator(()=>Files.newDirectoryStream(path).asScala.iterator)
        .map(LogInfo.fromPath)
        .collect({case Some(logInfo)=>logInfo})
        .map(_.asJson.noSpaces + "\n")
        .map(ByteString.apply)
      Result(
        header = ResponseHeader(200, Map.empty),
        body = HttpEntity.Streamed(stream, None, Some("application/x-ndjson"))
      )
    }
  }