From d78788171a11957de216180d9818941ada409ff2 Mon Sep 17 00:00:00 2001 From: peckover <56835853+peckover@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:12:37 +0100 Subject: [PATCH] [DL-8876] revise logging --- app/utils/LegacyErrorHandler.scala | 2 +- app/v1/controllers/requestParsers/RequestParser.scala | 6 +++--- app/v1/nrs/NrsConnector.scala | 4 ++-- app/v1/services/EnrolmentsAuthService.scala | 10 +++++----- app/v1/support/DesResponseMappingSupport.scala | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/utils/LegacyErrorHandler.scala b/app/utils/LegacyErrorHandler.scala index dbe23051..0c8e323b 100644 --- a/app/utils/LegacyErrorHandler.scala +++ b/app/utils/LegacyErrorHandler.scala @@ -43,7 +43,7 @@ class LegacyErrorHandler @Inject()(env: Environment, case _: NotImplementedException => NotImplemented(Json.toJson(DownstreamError)) case _ => - logger.info(s"[LegacyErrorHandler][onServerError] uncaught 5xx Exception") + logger.warn(s"[LegacyErrorHandler][onServerError] uncaught 5xx Exception") result } } diff --git a/app/v1/controllers/requestParsers/RequestParser.scala b/app/v1/controllers/requestParsers/RequestParser.scala index 7673b45f..63ad5c86 100644 --- a/app/v1/controllers/requestParsers/RequestParser.scala +++ b/app/v1/controllers/requestParsers/RequestParser.scala @@ -29,15 +29,15 @@ trait RequestParser[Raw <: RawData, Request] extends Logging { def parseRequest(data: Raw)(implicit correlationId: String): Either[ErrorWrapper, Request] = { validator.validate(data) match { case Nil => - logger.info(message = "[RequestParser][parseRequest] " + + logger.debug(message = "[RequestParser][parseRequest] " + s"Validation successful for the request with correlationId : $correlationId") Right(requestFor(data)) case err :: Nil => - logger.info(message = "[RequestParser][parseRequest] " + + logger.debug(message = "[RequestParser][parseRequest] " + s"Validation failed with ${err.code} error for the request with correlationId : $correlationId") Left(ErrorWrapper(correlationId, err, None)) case errs => - logger.info("[RequestParser][parseRequest] " + + logger.debug("[RequestParser][parseRequest] " + s"Validation failed with ${errs.map(_.code).mkString(",")} errors for the request with correlationId : $correlationId") Left(ErrorWrapper(correlationId, BadRequestError, Some(errs))) } diff --git a/app/v1/nrs/NrsConnector.scala b/app/v1/nrs/NrsConnector.scala index 98085a6d..302ec228 100644 --- a/app/v1/nrs/NrsConnector.scala +++ b/app/v1/nrs/NrsConnector.scala @@ -50,7 +50,7 @@ class NrsConnector @Inject()(val httpClient: HttpClient, } retry(appConfig.nrsRetries, retryCondition) { attemptNumber => - logger.info(s"Attempt $attemptNumber NRS submission: sending POST request to $url") + logger.info(s"Attempt $attemptNumber NRS submission: sending POST request to $url. CorrelationId: $correlationId") httpClient .POST[NrsSubmission, HttpResponse](url, nrsSubmission, Seq("X-API-Key" -> apiKey)) @@ -58,7 +58,7 @@ class NrsConnector @Inject()(val httpClient: HttpClient, val status = response.status if (Status.isSuccessful(status)) { - logger.info("NRS submission successful") + logger.info(s"NRS submission successful. CorrelationId: $correlationId") Right(response.json.as[NrsResponse]) } else { logger.warn(s".CorrelationId: $correlationId\tRequestId:${hc.requestId}\nNRS submission failed with error: ${response.body}") diff --git a/app/v1/services/EnrolmentsAuthService.scala b/app/v1/services/EnrolmentsAuthService.scala index 6434393c..06b51583 100644 --- a/app/v1/services/EnrolmentsAuthService.scala +++ b/app/v1/services/EnrolmentsAuthService.scala @@ -45,8 +45,8 @@ class EnrolmentsAuthService @Inject()(val connector: AuthConnector) extends Logg case Some(Individual) ~ enrolments => createUserDetailsWithLogging(affinityGroup = "Individual", enrolments) case Some(Organisation) ~ enrolments => createUserDetailsWithLogging(affinityGroup = "Organisation", enrolments) case Some(Agent) ~ enrolments => createUserDetailsWithLogging(affinityGroup = "Agent", enrolments) - case _ => - logger.warn(s"[AuthorisationService] [authoriseAsClient] Authorisation failed due to unsupported affinity group.") + case affinityGroup => + logger.warn(s"[AuthorisationService] [authoriseAsClient] Authorisation failed due to unsupported affinity group. $affinityGroup") Future.successful(Left(LegacyUnauthorisedError)) }recoverWith unauthorisedError } else { @@ -77,8 +77,8 @@ class EnrolmentsAuthService @Inject()(val connector: AuthConnector) extends Logg ) createUserDetailsWithLogging(affinityGroup = affGroup.get.toString, enrolments, Some(identityData)) - case _ => - logger.warn(s"[EnrolmentsAuthService] [authorised with nrsRequired = true] Authorisation failed due to unsupported affinity group.") + case affinityGroup => + logger.warn(s"[EnrolmentsAuthService] [authorised with nrsRequired = true] Authorisation failed due to unsupported affinity group. $affinityGroup") Future.successful(Left(LegacyUnauthorisedError)) }recoverWith unauthorisedError @@ -91,7 +91,7 @@ class EnrolmentsAuthService @Inject()(val connector: AuthConnector) extends Logg identityData: Option[IdentityData] = None): Future[Right[MtdError, UserDetails]] = { val clientReference = getClientReferenceFromEnrolments(enrolments) - logger.info(s"[AuthorisationService] [authoriseAsClient] Authorisation succeeded as" + + logger.debug(s"[AuthorisationService] [authoriseAsClient] Authorisation succeeded as" + s"fully-authorised organisation for VRN $clientReference.") val userDetails = UserDetails( diff --git a/app/v1/support/DesResponseMappingSupport.scala b/app/v1/support/DesResponseMappingSupport.scala index 7d1493c3..9a45cc2f 100644 --- a/app/v1/support/DesResponseMappingSupport.scala +++ b/app/v1/support/DesResponseMappingSupport.scala @@ -45,7 +45,7 @@ trait DesResponseMappingSupport { implicit logContext: EndpointLogContext): ErrorWrapper = { lazy val defaultErrorCodeMapping: String => MtdError = { code => - logger.info(s"[${logContext.controllerName}] [${logContext.endpointName}] - No mapping found for error code $code") + logger.warn(s"[${logContext.controllerName}] [${logContext.endpointName}] - No mapping found for error code $code") DownstreamError }