Skip to content

Commit

Permalink
Merge pull request #841 from gatorcse/analyzable-tags
Browse files Browse the repository at this point in the history
Analyzable tags
  • Loading branch information
rossabaker authored May 23, 2024
2 parents ecdc414 + b298fc8 commit d31c172
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ object PagingSelfAwareStructuredLogger {
private val pageSize = pageSizeK * 1024

private def pagedLogging(
loggingOp: (=> String) => F[Unit],
logOpWithCtx: Map[String, String] => (=> String) => F[Unit],
ctx: Map[String, String],
logSplitId: String,
msg: => String
): F[Unit] = {
val numOfPagesRaw = (msg.length - 1) / pageSize + 1
val numOfPages = Math.min(numOfPagesRaw, maxPageNeeded)
if (numOfPages <= 1)
loggingOp(msg)
logOpWithCtx(addPageCtx(msg, 1, 1, ctx))(msg)
else {
val logSplitIdPart1 = logSplitId.split('-').head
val pageHeaderTail = s"$numOfPages $logSplitIdPart1"
Expand All @@ -105,39 +106,55 @@ object PagingSelfAwareStructuredLogger {
val beginIndex = (pi - 1) * pageSize
val pageContent = msg.slice(beginIndex, beginIndex + pageSize)

loggingOp(show"""Page $pi/$pageHeaderTail
val page = show"""Page $pi/$pageHeaderTail
|
|$pageContent
|
|Page $pi/$pageFooterTail""".stripMargin)
|Page $pi/$pageFooterTail""".stripMargin

logOpWithCtx(addPageCtx(page, pi, numOfPages, ctx))(page)
}
}
}

private def addCtx(
private def addMsgCtx(
msg: => String,
ctx: Map[String, String]
): F[(String, Map[String, String])] =
randomUUID.map { uuid =>
val logSplitId = uuid.show
val msgLength = msg.length.show
(
logSplitId,
ctx
.updated(logSplitIdN, logSplitId)
.updated("page_size", s"${pageSizeK.show} Kib")
.updated("log_size", s"${msg.length.show} Byte")
.updated("whole_message_size_bytes", msgLength)
// The following is deprecated
.updated("log_size", s"${msgLength} Byte")
)
}

private def addPageCtx(
page: => String,
pageNum: => Int,
totalPages: => Int,
ctx: Map[String, String]
): Map[String, String] =
ctx
.updated("total_pages", totalPages.show)
.updated("page_num", pageNum.show)
.updated("log_size_bytes", page.length.show)

private def doLogging(
loggingLevelChk: => F[Boolean],
logOpWithCtx: Map[String, String] => (=> String) => F[Unit],
msg: => String,
ctx: Map[String, String] = Map()
): F[Unit] = {
loggingLevelChk.ifM(
addCtx(msg, ctx).flatMap { case (logSplitId, newCtx) =>
pagedLogging(logOpWithCtx(newCtx), logSplitId, msg)
addMsgCtx(msg, ctx).flatMap { case (logSplitId, newCtx) =>
pagedLogging(logOpWithCtx, newCtx, logSplitId, msg)
},
Applicative[F].unit
)
Expand Down

0 comments on commit d31c172

Please sign in to comment.