PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/dos/app/controllers/dos/ui/Logs.scala

https://github.com/delving/culture-hub
Scala | 44 lines | 34 code | 6 blank | 4 comment | 8 complexity | 5276bc9feeadb7cdbc191c4aa7504cdb MD5 | raw file
  1. package controllers.dos.ui
  2. import models.dos._
  3. import com.mongodb.casbah.Imports._
  4. import play.api.mvc._
  5. import extensions.Extensions
  6. import com.novus.salat.dao.SalatMongoCursor
  7. import controllers.MultitenancySupport
  8. /**
  9. *
  10. * @author Manuel Bernhardt <bernhardt.manuel@gmail.com>
  11. */
  12. object Logs extends Controller with Extensions with MultitenancySupport {
  13. def list(taskId: ObjectId, lastCount: Option[Int]) = MultitenantAction {
  14. implicit request =>
  15. val cursor: SalatMongoCursor[Log] = Log.dao.find(MongoDBObject("task_id" -> taskId)).limit(500).sort(MongoDBObject("date" -> 1))
  16. val (logs, skipped) = if (lastCount != None && lastCount.get > 0) {
  17. if (cursor.count - lastCount.get > 100) {
  18. (cursor.skip(cursor.count - 100), true)
  19. } else {
  20. (cursor.skip(lastCount.get + 1), false)
  21. }
  22. } else {
  23. if (cursor.count > 100) {
  24. (cursor.skip(cursor.count - 100), true)
  25. } else {
  26. (cursor, false)
  27. }
  28. }
  29. Json(Map("logs" -> logs.toList, "skipped" -> skipped))
  30. }
  31. def view(taskId: ObjectId) = MultitenantAction {
  32. implicit request =>
  33. {
  34. val cursor: SalatMongoCursor[Log] = Log.dao.find(MongoDBObject("task_id" -> taskId)).sort(MongoDBObject("date" -> 1))
  35. Ok(cursor.map(log => log.date + "\t" + s"[${log.orgId}] " + log.level.name.toUpperCase + "\t" + log.node + "\t" + log.message).mkString("\n"))
  36. }
  37. }
  38. }