package gitbucket.monitoring.controllers

import gitbucket.monitoring.services.{LogBack, GitBucketLog}
import gitbucket.monitoring.information.logs._

trait LogController extends MonitoringControllerBase {

  get("/admin/monitoring/logs/logback")(adminOnly {
    gitbucket.monitoring.information.logs.html.logback(
      LogBack.getLogBackInfo,
      LogBack.getLogBackSettings
    );
  })

  get("/admin/monitoring/logs/gitbucketlog")(adminOnly {
    val defaultSettings = GitBucketLog.getDefaultSettings
    val lineNum = request.getParameter("numOfDisplayLogLines")

    if (lineNum != null){
      try {
        val n = lineNum.toInt
        if (n > defaultSettings.displayLimitLines) {
          html.gitbucketlog(defaultSettings, os.getLog(defaultSettings.displayLimitLines));
        } else {
          html.gitbucketlog(defaultSettings, os.getLog(n));
        }
      } catch {
        case e: Exception => html.gitbucketlog(defaultSettings, os.getLog());
      }
    } else {
      html.gitbucketlog(defaultSettings, os.getLog());
    }
  })
}
package gitbucket.monitoring.controllers

import gitbucket.monitoring.services.{LogBack, GitBucketLog}
import gitbucket.monitoring.information.logs._

trait LogController extends MonitoringControllerBase {

  get("/admin/monitoring/logs/logback")(adminOnly {
    gitbucket.monitoring.information.logs.html.logback(
      LogBack.getLogBackInfo,
      LogBack.getLogBackSettings
    );
  })

  get("/admin/monitoring/logs/gitbucketlog")(adminOnly {
    val defaultSettings = GitBucketLog.getDefaultSettings
    val lineNum = request.getParameter("numOfDisplayLogLines")

    if (Option(lineNum) != None){
      try {
        val n = lineNum.toInt
        if (n > defaultSettings.displayLimitLines) {
          html.gitbucketlog(defaultSettings, os.getLog(defaultSettings.displayLimitLines));
        } else {
          html.gitbucketlog(defaultSettings, os.getLog(n));
        }
      } catch {
        case e: Exception => html.gitbucketlog(defaultSettings, os.getLog());
      }
    } else {
      html.gitbucketlog(defaultSettings, os.getLog());
    }
  })
}
Use Option to check input value
Use Option to check input value
