private def logAround[T]()

in admin/app/dfp/SessionLogger.scala [34:94]


  private def logAround[T](typesName: String, opName: String, statement: Option[Statement] = None)(
      op: => T,
  )(numAffected: T => Int): Option[T] = {

    def logApiException(e: ApiException, baseMessage: String): Unit = {
      e.getErrors foreach { err =>
        val reasonMsg = err match {
          case freqCapErr: FrequencyCapError => s", with the reason '${freqCapErr.getReason}'"
          case notNullErr: NotNullError      => s", with the reason '${notNullErr.getReason}'"
          case _                             => ""
        }
        val path = err.getFieldPath
        val trigger = err.getTrigger
        val msg = s"'${err.getErrorString}'$reasonMsg"
        log.error(
          s"$baseMessage failed: API exception in field '$path', " +
            s"caused by an invalid value '$trigger', " +
            s"with the error message $msg",
          e,
        )
      }
    }

    val maybeQryLogMessage = statement map { stmt =>
      val qry = stmt.getQuery
      val params = stmt.getValues.map { param =>
        val k = param.getKey
        val rawValue = param.getValue
        k -> (
          rawValue match {
            case t: TextValue    => s""""${t.getValue}""""
            case n: NumberValue  => n.getValue
            case b: BooleanValue => b.getValue
            case other           => other.toString
          }
        )
      }.toMap
      val paramStr = if (params.isEmpty) "" else s"and params ${params.toString}"
      s"""with statement "$qry" $paramStr"""
    }
    val baseMessage = s"$opName $typesName"
    val msgPrefix = maybeQryLogMessage map (qryLogMsg => s"$baseMessage $qryLogMsg") getOrElse baseMessage

    try {
      log.info(s"$msgPrefix ...")
      val start = System.currentTimeMillis()
      val result = op
      val duration = System.currentTimeMillis() - start
      log.info(s"Successful $opName of ${numAffected(result)} $typesName in $duration ms")
      Some(result)
    } catch {
      case e: ApiException =>
        logApiException(e, msgPrefix);
        DfpApiErrors.increment();
        None
      case NonFatal(e) =>
        log.error(s"$msgPrefix failed", e);
        DfpApiErrors.increment();
        None
    }
  }